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.