Questions tagged [unrecognized-selector]

"Unrecognized selector" is an exception in Cocoa and Cocoa Touch, thrown when an object receives a message to which it cannot respond.

"Unrecognized selector" is an exception in Cocoa and Cocoa Touch, thrown when an object receives a message to which it cannot respond.

This most often means that the object is not of the expected class. For example,

NSDictionary * d = @{@"item_code" : @45};
NSString * code = d[@"item_code"];
NSLog(@"%@", [code uppercaseString]);

will raise this exception, saying

-[__NSCFNumber uppercaseString:]: unrecognized selector sent to instance 0x9028390

because the object is an NSNumber, not an NSString despite the type of the pointer.

For useful debugging procedures, see How can I debug 'unrecognized selector sent to instance' error

578 questions
175
votes
41 answers

"unrecognized selector sent to instance" error in Objective-C

I created a button and added an action for it, but as soon as it invoked, I got this error: -[NSCFDictionary numberButtonClick:]: unrecognized selector sent to instance 0x3d03ac0 2010-03-16 22:23:58.811 Money[8056:207] *** Terminating app due to…
HelloWorld
  • 7,156
  • 6
  • 39
  • 36
51
votes
4 answers

NSURLSession dataTaskForRequest:completion: unrecognized selector sent to instance

When trying to create my own session object NSURLSession() and request an url I get an unrecognized selector exception but when I use the shared session NSURLSession.sharedSession() everything works fine. How come? var url = NSURL(string:…
Alexey
  • 7,127
  • 9
  • 57
  • 94
22
votes
5 answers

Unrecognized selector sent to instance while archiving data (NSCoding)

-(void)transformObjects:(NSMutableArray*)array key:(NSString*)key { NSMutableArray* archiveArray = [[NSMutableArray alloc]initWithCapacity:array.count]; for (Furniture *furniture in array) { // The error occurs on the line below …
SteBra
  • 4,188
  • 6
  • 37
  • 68
17
votes
2 answers

iPhone: Category with property + "unrecognized selector sent to instance" exception

First of all I have seen that there are many questions about "unrecognized selector sent to instance" issue. I have seen few but saw nothing about accessing a defined in category property... I have a category on UILabel with a property. The getter…
17
votes
1 answer

-[_NSObserverList setCursorPosition:]

I am getting #560 NSInvalidArgumentException error as shown below; -[_NSObserverList setCursorPosition:]: unrecognized selector sent to instance 0x1702a6ea0 CoreFoundation ___exceptionPreprocess Fatal Exception: NSInvalidArgumentException 0 …
15
votes
5 answers

Under what conditions might instancesRespondToSelector: return true, but performSelector: throw an exception

I have code distributed in a library which looks like this: if ([[NSString class] instancesRespondToSelector: @selector(JSONValue)]) { NSString *jsonString = [[[NSString alloc] initWithData: jsonData encoding: NSUTF8StringEncoding] autorelease]; …
ThomasW
  • 16,981
  • 4
  • 79
  • 106
14
votes
2 answers

Unrecognized selector calling category method in static iOS library

I am using some third party software to aid in writing an iPad application using Xcode 4.3.2. The software is open source and is usually set up so its code will be compiled along with whatever code the developer writes for the application. Because I…
Tron Thomas
  • 871
  • 7
  • 20
11
votes
1 answer

Breaking on unrecognized selector

Is it possible to set a break point on this bit of feedback in the console? This would make handling this problem so much easier.
Hyperbole
  • 3,917
  • 4
  • 35
  • 54
11
votes
4 answers

Why am I getting unrecognized selector sent to class?

I have been going through all stack overflow trying to solve this but none of the solutions work. class ToastView: UIView { static func showInParent(parentView: UIView!, withText text: String, forDuration duration: double_t) { //Count…
10
votes
2 answers

"unrecognized selector sent to class" when calling category method from a library

Problem This question may seem a bit long, but I try to give as much information as possible, since I am really staggered by this. I am currently working an a library which should automate XML document parsing. But I am running into a problem now…
9
votes
6 answers

Using global variables in Objective-C

First of all, I tried almost all the solutions given in stackoverflow but I didn't succeed in implement global vars, I even did a step by step tutorial and still I get the same errors. heres the issue: I have a program with severals views, I'd like…
izzy
  • 185
  • 1
  • 1
  • 9
9
votes
3 answers

How to use a predicate on NSTimeInterval?

I would like to get all records for the current month, so I stack two predicates for first date of the month and last day of the month. Since I use CoreData the dates are stored actually as NSTimeInterval. NSCalendar *calendar = [NSCalendar…
Houman
  • 64,245
  • 87
  • 278
  • 460
8
votes
2 answers

__NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance

I'm trying to calculate duration difference between two times. I get the durations from JSONArray. I use the below code NSDate *starttime = [[NSDate alloc]init]; NSDate *endtime = [[NSDate alloc]init]; starttime = [currentRecord…
Jeeva
  • 1,791
  • 2
  • 23
  • 42
7
votes
2 answers

Unrecognized Selector Sent to Instance [NSCFString subarrayWithRange:]

I have the following code which is producing this error. I cannot understand why the subarrayWithRange message is being sent to a string? When it is clearly an array? static const int kItemsPerView = 20; NSRange rangeForView = NSMakeRange( page *…
joec
  • 3,533
  • 10
  • 60
  • 89
7
votes
2 answers

[__NSCFType searchKeyword:]: unrecognized selector sent to instance 0x6d8eb80

The following code is to add a subview to current view from storyboard: EventSearchViewController* view1 = [self.storyboard instantiateViewControllerWithIdentifier:@"searchView"]; [view1 setBookingSystem:system]; [self.view…
1
2 3
38 39