Zhen Zhen - 2 years ago 94
Objective-C Question

Objective C: How to resolve 'unrecognized selector sent to instance' error

I am trying to access a property of instance object using the following code

for (User *user in likersArray)
//Set variables for dictionary
NSString *nameLength = [NSString stringWithFormat:@"%i",[user.nickname length]];

However, I keep getting the following error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString nickname]: unrecognized selector sent to instance 0x8c0f780'

My user class is defined as below

@interface User : NSObject <NSCoding>
NSString *uid;
NSString *name;
NSString *nickname;

@property (nonatomic, copy) NSString *uid;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *nickname;


Answer Source

That error means that not everything in your likersArray is a User object. At least one thing in there is an NSString.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download