nsarray 中自定义对象 NSString 属性的唯一值

发布于 2024-09-28 22:48:31 字数 669 浏览 2 评论 0原文

我有一个存储自定义对象的数组。 对象属于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

裸钻 2024-10-05 22:48:31

这是因为 venueArray 中至少有一个 NSString 对象。

确保 venueArray 中的每个元素都是 Venue 类型。

This is because there is at least one NSString object in venueArray.

Make sure that every element in your venueArray is of type Venue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文