您的位置:首页 > 移动开发 > Objective-C

objc_getAssociatedObject 出现异常

2015-10-09 14:53 411 查看
定义属性

@property (nonatomic, assign) NSInteger unreadCount;


使用运行时关联对象

- (NSInteger)unreadCount {
return [objc_getAssociatedObject(self, @selector(unreadCount)) intValue]; <span style="color:#ff0000;">//运行至此处报错</span>
}

- (void)setUnreadCount:(NSInteger)unreadCount {
objc_setAssociatedObject(self, @selector(unreadCount), @(unreadCount), OBJC_ASSOCIATION_ASSIGN);
}


出现以下报错:

-[NSConcreteValue intValue]: unrecognized selector sent to instance 0x16604de0

libc++abi.dylib: terminate_handler unexpectedly threw an exception

解决方法:

将 OBJC_ASSOCIATION_ASSIGN 改成 OBJC_ASSOCIATION_RETAIN
即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: