我有一个看起来像这样的简单对象:
#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
这是实现:
#import "MyCycle.h"
@implementation MyCycle
@end
这是用户对象:
#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
我分配这个对象并用以下内容填充它:
MyCycle *cycle = [[MyCycle alloc] init];
cycle.myNumber = @1;
cycle.data = [[NSArray alloc]init];
我收到以下错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyCycle copyWithZone:]: unrecognized selector sent to instance
为什么会发生这种情况,我该如何解决?
最佳答案
在您的代码中的某处,您有一个尝试复制 MyCycle
实例的代码。也许您使用对象作为字典的键?如果你想继续这种行为,你需要为你的类实现 NSCopying protocol 。
关于ios - 在 iOS 中创建新对象会引发 copywithzone 无法识别的选择器错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21491322/