KVC with NSArrays of NSArrays

廉价感情. 提交于 2019-12-06 08:05:23

问题


I have an array of arrays that I want to use KVC on (at least I think I do -- it seems like the most straightforward way) but I can't figure out how to create keypaths for individual array indexes. My array looks like this

NSArray [

NSArray[0, 1, 2, 3], NSArray[4, 5, 6, 7], NSArray[8, 9, 10, 11]

]

What I want to do is get the maximum value of index 3 in the inner array. It seems like something like [outerArray valueForKey:@"@max.[3]"] would work, but I can't figure out the syntax, and my Googling has been fruitless as well. Is what I'm trying to do even possible, or should I just write a method to do this manually?


回答1:


Most people expect this to be there, but KVC really doesn't allow addressing individual indexes of an array. You can operate on the whole array or transformations of the array (e.g, @distinctUnionOfArrays) but you can't address individual elements. You'll have to do it "by hand," so to speak.



来源:https://stackoverflow.com/questions/3081632/kvc-with-nsarrays-of-nsarrays

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!