开发者

Smart way to search an array of arrays

开发者 https://www.devze.com 2022-12-28 19:56 出处:网络
I have an array of arrays with objects 开发者_如何转开发and now want to get all objects for a certain date (which is an object property).

I have an array of arrays with objects 开发者_如何转开发and now want to get all objects for a certain date (which is an object property).

what's the best way to query it?


In this case you have to make a double for-loop with fast enumeration and look into each object.

for(NSArray* anArray in yourArray) {

    for(id aObject in anArray) {
      //compare date
    }

}

Maybe it would be better if you exchange the first array with a dictionary which keys are dates. For each key in the dictionary you store an array with objects whose date is the same as in the dictionary key. With that you won't have to look at each single object.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号