Note that there are some explanatory texts on larger screens.

plurals
  1. POunrecognized selector from protocol
    primarykey
    data
    text
    <p>UPDATE: Issue found, solution found and marked as answer.</p> <p>Issue is that I use a static method of the superclass to initialize, thus turning it into the superclass instead of subclass.</p> <p>END UPDATE:</p> <p>I have a protocol, a class that implements that protocol, and then a class that creates an instance of the protocol'd class that calls the protocol method. I am receiving an "Unrecognized selector sent to instance..." when invoking that protocol method.</p> <p>Note: I am using ArcGIS for displaying a map, but that should be irrelevant to my problem.</p> <p>The protocol method (<code>layerName</code>) works later during runtime on another object that implements LayerProtocol.</p> <p>Example Code:</p> <pre><code>@protocol LayerProtocol &lt;NSObject&gt; - (NSString *) layerName; @end @interface StreetLayer: AGSTiledMapServiceLayer&lt;LayerProtocol&gt; @end @implementation StreetLayer - (id) init { self = [AGSTiledMapServiceLayer tiledMapServiceLayerWithURL: [NSURL URLWithString: [NSString stringWithFormat: @"%@%@", @"https://server.arcgisonline.com/ArcGIS/", @"rest/services/World_Street_Map/MapServer"] ]]; return self; } - (NSString *) layerName { return @"Street Layer"; } @end @interface MapContainerViewController: UIViewController @property (nonatomic) AGSMapView * mapView; @property (nonatomic) StreetLayer * layer; @end @implementation MapContainerViewController - (void) viewDidLoad { _mapView = [[AGSMapView alloc] init]; _layer = [[StreetLayer alloc] init]; [mapView addMapLayer:_layer withName:[_layer layerName]]; } </code></pre> <p>The error occurs on the access to <code>[_layer layerName]</code></p> <p>I feel like I'm missing something really obvious here.</p> <p>I do know that AGSLayer has an access to the name of the layer, that is irrelevant to the problem.</p> <p>Additionally, I have used <code>[_layer respondsToSelector:@selector(layerName)]</code> and it fails that check.</p> <p>STACK TRACE:</p> <p><em>*</em> Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AGSTiledMapServiceLayer layerName]: unrecognized selector sent to instance 0xbe7ef90'</p> <p><em>*</em> First throw call stack: (</p> <pre><code>0 CoreFoundation 0x035105e4 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x032938b6 objc_exception_throw + 44 2 CoreFoundation 0x035ad903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275 3 CoreFoundation 0x0350090b ___forwarding___ + 1019 4 CoreFoundation 0x035004ee _CF_forwarding_prep_0 + 14 5 MyProject 0x00061d95 -[MapContainerViewController mapTypeToggled:] + 677 6 libobjc.A.dylib 0x032a5874 -[NSObject performSelector:withObject:withObject:] + 77 7 UIKit 0x01522c8c -[UIApplication sendAction:to:from:forEvent:] + 108 8 UIKit 0x01522c18 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61 9 UIKit 0x0161a6d9 -[UIControl sendAction:to:forEvent:] + 66 10 UIKit 0x0161aa9c -[UIControl _sendActionsForEvents:withEvent:] + 577 11 UIKit 0x01619d4b -[UIControl touchesEnded:withEvent:] + 641 12 UIKit 0x015600cd -[UIWindow _sendTouchesForEvent:] + 852 13 UIKit 0x01560d34 -[UIWindow sendEvent:] + 1232 14 UIKit 0x01534a36 -[UIApplication sendEvent:] + 242 15 UIKit 0x0151ed9f _UIApplicationHandleEventQueue + 11421 16 CoreFoundation 0x034998af __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15 17 CoreFoundation 0x0349923b __CFRunLoopDoSources0 + 235 18 CoreFoundation 0x034b630e __CFRunLoopRun + 910 19 CoreFoundation 0x034b5b33 CFRunLoopRunSpecific + 467 20 CoreFoundation 0x034b594b CFRunLoopRunInMode + 123 21 GraphicsServices 0x051d49d7 GSEventRunModal + 192 22 GraphicsServices 0x051d47fe GSEventRun + 104 23 UIKit 0x0152194b UIApplicationMain + 1225 24 GmcSeeds 0x00073b1d main + 141 25 libdyld.dylib 0x03a7f725 start + 0 </code></pre> <p>) libc++abi.dylib: terminating with uncaught exception of type NSException</p> <pre><code>- (void) mapTypeToggled:(id)sender { _streetViewToggled = !_streetViewToggled; if (_streetViewToggled) { // show street view [_mapView removeMapLayer:_satelliteLayer]; [_mapView insertMapLayer:_streetLayer withName:[_streetLayer layerName] atIndex:0]; } else { // show satellite view [_mapView removeMapLayer:_streetLayer]; [_mapView insertMapLayer:_satelliteLayer withName:[_satelliteLayer layerName] atIndex:0]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload