Amit Pandey
Amit Pandey

Reputation: 166

Objective C and Swift in same Project - -[__NSCFNumber length]: unrecognized selector sent to instance

I am new in Swift, I have my appDelegate file in Objective-C and my current controller is in Swift. The issue is I have a property in my appdelegate as USER_ID to contain login user id and a token property as AUTH_TOKEN.

@property (nonatomic, strong) NSString * USER_ID;
@property (nonatomic, strong) NSString * AUTH_TOKEN;

I want these values on my Swift controller. For this I have an instance of current appDelegate like:

let APP_DELEGATE_SWIFT = UIApplication.shared.delegate as! AppDelegate 

and now when I print these to value on Swift controller like:

print("AuthToken - \(APP_DELEGATE_SWIFT.auth_TOKEN!)")
print("user id - \(APP_DELEGATE_SWIFT.user_ID!)")

I am able to get value of auth_TOKEN, but in the case of user_ID, it gives me error like:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000036783'

Upvotes: 1

Views: 931

Answers (1)

Neeraj Sonaro
Neeraj Sonaro

Reputation: 346

Error indicates you are using a NSString method on a NSNumber. Please, check if your data are strings.

Upvotes: 2

Related Questions