KVC 与 NSArrays 的 NSArrays

发布于 2024-09-06 13:09:29 字数 318 浏览 2 评论 0原文

我有一个数组数组,我想在其上使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟织青萝梦 2024-09-13 13:09:29

大多数人都希望它存在,但 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文