Order two NSMutableArrays based on one

前端 未结 2 405
庸人自扰
庸人自扰 2020-12-03 16:19

I have two NSMutableArrays. The content of the first is numerically, which is paired to the content of the second one:

First Array    Second Array
   45              


        
2条回答
  •  忘掉有多难
    2020-12-03 16:43

    Rather than keep two parallel arrays, I'd keep a single array of model objects. Each number from the first array would be the value of one property, and each string from the second array would be the value of the other property. You could then sort on either or both properties using sort descriptors.

    Generally, in Cocoa and Cocoa Touch, parallel arrays make work while model objects save work. Prefer the latter over the former wherever you can.

提交回复
热议问题