KVC 与 NSArrays 的 NSArrays
我有一个数组数组,我想在其上使用 KVC(至少我认为我这样做——这似乎是最直接的方法),但我不知道如何为各个数组索引创建键路径。我的数组看起来像这样
NSArray [
NSArray[0, 1, 2, 3], NSArray[4,5,6,7], NSArray[8, 9, 10, 11]
]
我想要做的是获取内部数组中索引 3 的最大值。似乎 [outerArray valueForKey:@"@max.[3]"] 之类的东西可以工作,但我无法弄清楚语法,而且我的谷歌搜索也毫无结果。我想要做的事情是否可能,或者我应该编写一个方法来手动执行此操作?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
大多数人都希望它存在,但 KVC 确实不允许寻址数组的各个索引。您可以对整个数组或数组的转换进行操作(例如,
@distinctUnionOfArrays
),但无法对单个元素进行寻址。可以这么说,你必须“手工”完成。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.