Creating a new object throws copywithzone unrecognized selector error in iOS

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 select this object and fill it as follows:

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?

+3
source share
4 answers

Somewhere in your code, you have code that is trying to copy an instance MyCycle. Perhaps you are using an object as a key for a dictionary? If you want to continue this behavior, you need to implement the NSCopying protocol for your class.

+6
source

, , - , , SDK iOS. . , XCode ( Objective C).

0

, , , . . , Interface Builder, , - copyWithZone:.

, File Owner innerController innerController.property.

0

This is an old question, but you probably don't have @synthesized property data ',' myNumber '. In other words, you have no settings for these properties.

0
source

All Articles