Objective C:如何解决“发送到实例的无法识别的选择器”问题错误
我尝试使用以下代码访问实例对象的属性
for (User *user in likersArray)
{
//Set variables for dictionary
NSString *nameLength = [NSString stringWithFormat:@"%i",[user.nickname length]];
}
但是,我不断收到以下错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString nickname]: unrecognized selector sent to instance 0x8c0f780'
我的用户类定义如下
@interface User : NSObject <NSCoding>
{
NSString *uid;
NSString *name;
NSString *nickname;
}
@property (nonatomic, copy) NSString *uid;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *nickname;
@end
I am trying to access a property of instance object using the following code
for (User *user in likersArray)
{
//Set variables for dictionary
NSString *nameLength = [NSString stringWithFormat:@"%i",[user.nickname length]];
}
However, I keep getting the following error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString nickname]: unrecognized selector sent to instance 0x8c0f780'
My user class is defined as below
@interface User : NSObject <NSCoding>
{
NSString *uid;
NSString *name;
NSString *nickname;
}
@property (nonatomic, copy) NSString *uid;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *nickname;
@end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这也可能意味着
likersArray
中的一个User
对象被过度释放,并且您遇到了垃圾。It could also mean that one of the
User
objects inlikersArray
is being over-released and you are hitting garbage.我遇到了一个非常类似的问题,这是由于只创建了一项并将其插入数组而引起的。如果您的 likersArray 仅包含 1 个项目,它也会导致此错误,并且这是一个很难找到的错误。希望这对某人有帮助!
I had a very similar issue which was being caused due to only one item being created and inserted into the array. If your likersArray contains only 1 item it causes this error as well and it's a nasty bug to find. Hopefully this helps someone!
该错误意味着并非
likersArray
中的所有内容都是User
对象。其中至少有一个东西是一个NSString
。That error means that not everything in your
likersArray
is aUser
object. At least one thing in there is anNSString
.