creating new object throws copywithzone unrecognized selector error in iOS
cocoa-touch, ios, nsobject, objective-c
Solution
Somewhere in your code, you have a code that attempts to copy an `MyCycle` instance. Perhaps you use an object as a key to a dictionary? If you wish to continue with this behavior, you need to implement the NSCopying protocol for your class.
Problem
I have a simple object that looks like this: ``` #import <Foundation/Foundation.h> #import <Parse/Parse.h> @class MyUser; @interface MyCycle : NSObject @property (nonatomic, copy) NSNumber *myNumber; @property (nonatomic, strong) MyUser *user; @property (nonatomic, strong) NSArray *data; @end ``` Here is the implementation: ``` #import "MyCycle.h" @implementation MyCycle @end ``` Here is the user object: ``` #import <Foundation/Foundation.h> #import <Parse/Parse.h> @interface MyUser : NSObject @property (nonatomic, copy) NSString *usersName; @property (nonatomic, copy) NSString *gender; @property (nonatomic, copy) NSString *email; @property (nonatomic, copy) NSString *password; @property (nonatomic, copy) NSString *phoneNumber; @property (nonatomic, strong) UIImage *profileImage; @property (nonatomic, strong) PFFile *profileImageFile; @end ``` I allocate this object and populate it with the following: ``` MyCycle *cycle = [[MyCycle alloc] init]; cycle.myNumber = @1; cycle.data = [[NSArray alloc]init]; ``` I get the following error: ``` *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyCycle copyWithZone:]: unrecognized selector sent to instance ``` Why is this happening and how can I fix it?