Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[UILabel copyWithZone:]: unrecognized selector sent to instance [some_instance_id]

Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[UILabel copyWithZone:]: unrecognized selector sent to instance

This could be quite annoying bug for you when you know you have done nothing wrong. And your code is all so neat and clean.

Well, it isn’t actually. There is apparently no errors for you but when you compile and run the code you encounter a logical error.

How it appears?

Try adding a UILabel in you xib file. Declare it in your .h file as follows..

IBOutlet UILabel *text;

and then go back to xib and add reference to that label field. (I consider that you all know how to make UserInterface using the xcode GUI).
Compile and Run the code. The code breaks there stating the error (As mentioned in the title of this post).

There is absolutely nothing wrong in you code logic, except for one teeni tiny thing. The name of the variable you declare for that UILabel is already used by the iOS SDK. You can say it’s a keyword. And the variable name can never be a keyword because it confuses your XCode (Objective C Compiler).

Try changing the code (in .h file) to something like below:

IBOutlet UILabel *label_text;

It’s always a good practice to add a prefix/postfix to your variable name. That way you will know which view type you are referencing. Now go back to ur .xib class and second click file owner and attach a reference to your label view.

Run the code. It must work now!

If anyone of you encounter the same error but are not able to solve it in anyway or if you find a different solution, don’t forget to comment below. I’ll add up in this post.

Advertisements

2 thoughts on “Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[UILabel copyWithZone:]: unrecognized selector sent to instance [some_instance_id]

  1. I didn’t give any connection to program for label. Even though i got this error. please help me out of this error ” -[UILabel setDelegate:]: unrecognized selector sent to instance 0x185327d0″

  2. I didn’t give any connection to program for label. Even though i got this error. please help me out of this error ” -[UILabel setDelegate:]: unrecognized selector sent to instance 0x185327d0″ I have used text field that is connected via IBoutlet but i have used some label bu i didn’t connect to storyboard.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s