NSInvalidArgumentException,无法识别的选择器发送到实例的原因
NSInvalidArgumentException, reason unrecognized selector sent to instance
处理 json 响应时出现以下错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DADGList setDescription:]:
unrecognized selector sent to instance 0x7ae88880'
崩溃的class:
@implementation DADGList
-(id)copy
{
DADGList *list = [[DADGList alloc] init];
list.identifier = self.identifier;
list.name = [self.name copy];
list.description = [self.description copy];
list.created = [self.created copy];
list.itemCount = self.itemCount;
list.shareLink = [self.shareLink copy];
return list;
}
+(DADGList *)listFromDictonary:(NSDictionary *)dictonary
{
DADGList *list = [[DADGList alloc] init];
NSLog( @"%@", dictonary );
list.identifier = [[dictonary objectForKey:@"list_id"] integerValue];
list.itemCount = [[dictonary objectForKey:@"list_items_count"] integerValue];
list.name = [NSString stringWithString:[dictonary objectForKey:@"list_name"]];
list.description = [NSString stringWithString:[dictonary objectForKey:@"list_description"]];
list.created = [[NSDate alloc] initWithTimeIntervalSince1970:[[dictonary objectForKey:@"list_created"] doubleValue]];
list.shareLink = [NSString stringWithString:[dictonary objectForKey:@"list_share_url"]];
return list;
}
和 listFromDictonary 过去的字典:
您应该将 description
属性 重命名为其他名称,因为这是 iOS 回声系统(如果我没记错的话是 NSObject)中已经存在的字段,并且会创建所有类型像这样的奇怪崩溃。
如果您正在使用 core data
,您可能需要实施以下实例:
Mall(entity: NSEntityDescription.entity(forEntityName: "Mall", in: context)!, insertInto: nil)
其中 Mall
是我的实体,context
是我的视图上下文。
处理 json 响应时出现以下错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DADGList setDescription:]: unrecognized selector sent to instance 0x7ae88880'
崩溃的class:
@implementation DADGList
-(id)copy
{
DADGList *list = [[DADGList alloc] init];
list.identifier = self.identifier;
list.name = [self.name copy];
list.description = [self.description copy];
list.created = [self.created copy];
list.itemCount = self.itemCount;
list.shareLink = [self.shareLink copy];
return list;
}
+(DADGList *)listFromDictonary:(NSDictionary *)dictonary
{
DADGList *list = [[DADGList alloc] init];
NSLog( @"%@", dictonary );
list.identifier = [[dictonary objectForKey:@"list_id"] integerValue];
list.itemCount = [[dictonary objectForKey:@"list_items_count"] integerValue];
list.name = [NSString stringWithString:[dictonary objectForKey:@"list_name"]];
list.description = [NSString stringWithString:[dictonary objectForKey:@"list_description"]];
list.created = [[NSDate alloc] initWithTimeIntervalSince1970:[[dictonary objectForKey:@"list_created"] doubleValue]];
list.shareLink = [NSString stringWithString:[dictonary objectForKey:@"list_share_url"]];
return list;
}
和 listFromDictonary 过去的字典:
您应该将 description
属性 重命名为其他名称,因为这是 iOS 回声系统(如果我没记错的话是 NSObject)中已经存在的字段,并且会创建所有类型像这样的奇怪崩溃。
如果您正在使用 core data
,您可能需要实施以下实例:
Mall(entity: NSEntityDescription.entity(forEntityName: "Mall", in: context)!, insertInto: nil)
其中 Mall
是我的实体,context
是我的视图上下文。