“NSSet allObjects”随机排序吗?
我有以下代码:
self.temporaryImageArray = [(NSSet *)[[array objectAtIndex:0] images] allObjects]
Array 包含来自我的 CoreData 模型的 Band
对象。它有一个名为“images”的 NSSet
属性。
现在,我使用这个 temporaryImageArray 通过时间戳来确定图像是否需要更新。我遇到了一些非常随机的行为,现在我的问题是:
[NSSet allObjects]
是否以无顺序随机从集合中返回对象?
有什么办法可以防止这种情况或让它按顺序返回吗?这会大大降低我的代码的复杂性。
I have the following code:
self.temporaryImageArray = [(NSSet *)[[array objectAtIndex:0] images] allObjects]
Array holds an Band
object from my CoreData model. It has an NSSet
as a property called "images".
Now I use this temporaryImageArray
to determine via timestamps whether or not the images need to be updated. I have come across some very random behavior and my question now is:
Does [NSSet allObjects]
return the Objects from the Set randomly in no order?
Is there any way to prevent this or to have it return it in order? It would lessen the complexity of my code a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
NSSet
是一个无序集合。它不知道其对象的“顺序”是什么。因此,当您调用-allObjects
时,它会无序地返回它们。请注意,关于
-allObjects
的文档指出:(强调我的)
NSSet
is an unordered collection. It has no idea what the "order" of its objects are. Therefore, when you call-allObjects
, it returns them unordered.Note that the documentation on
-allObjects
states:(emphasis mine)
集合没有顺序。但是,在 10.7 (Lion) 中,有一个 NSOrderedSet 类。 iOS 4.0 中不提供此功能。
A set does not have order. However, in 10.7 (Lion), there is an NSOrderedSet class. This isn't available in iOS 4.0.
NSOrderedSet 和 NSMutableOrderedSet 现在在 iOS 5 中可用,以便您随时了解最新情况。
这是
NSOrderedSet and NSMutableOrderedSet are now available in iOS 5 just so you're kept up to date.
Here's the link