nsarray 中自定义对象 NSString 属性的唯一值
我有一个存储自定义对象的数组。 对象属于 Venue 类型,其属性定义为 name(其中包含场地名称)。
现在我想过滤掉具有唯一名称的对象。
这就是我试图做的。
NSSet *uniqueVenuesSet = [NSSet setWithArray:[venueArray valueForKey:@"name"]];
NSMutableArray *uniqueVenues = [[NSMutableArray alloc] initWithArray:[uniqueVenuesSet allObjects]]
;
当我运行这个时,我收到此错误。
-[NSCFString name]: unrecognized selector sent to instance 0x69a6190
2010-10-24 09:25:31.832 [75790:207] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString name]: unrecognized selector sent to instance 0x69a6190'
谁能给我指点一下如何去做。
I have an array which stores custom objects.
Objects are of type Venue which have a property defined as name(which contains the names of venue).
Now I want to filter out objects with unique names.
This is how I was trying to do.
NSSet *uniqueVenuesSet = [NSSet setWithArray:[venueArray valueForKey:@"name"]];
NSMutableArray *uniqueVenues = [[NSMutableArray alloc] initWithArray:[uniqueVenuesSet allObjects]]
;
I get this error when I run this.
-[NSCFString name]: unrecognized selector sent to instance 0x69a6190
2010-10-24 09:25:31.832 [75790:207] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString name]: unrecognized selector sent to instance 0x69a6190'
Can anyone give me a pointer on how to go about it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为
venueArray
中至少有一个NSString
对象。确保
venueArray
中的每个元素都是Venue
类型。This is because there is at least one
NSString
object invenueArray
.Make sure that every element in your
venueArray
is of typeVenue
.