Xcode自动完成功能会提示神秘的&"songsAtIndexes&"用于NSArray吸气剂 [英] Xcode auto-complete suggests mysterious "songsAtIndexes" for NSArray getter

查看:66
本文介绍了Xcode自动完成功能会提示神秘的&"songsAtIndexes&"用于NSArray吸气剂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的类上有一个名为NSArray的属性,称为歌曲".我正在为此创建一个自定义吸气剂,而XCode为我提供了创建方法的选项:

I have a property of type NSArray on my class called "songs". I'm creating a custom getter for it and XCode gives me an option of creating a method:

songsAtIndexes:(NSIndexSet *)indexes

这是什么,为什么XCode提供此功能?这是特定于NSArray属性吗?为该方法创建方法/获取器的目的是什么?如果我没有手动定义它,会自动创建/合成它吗?

What is this and why is XCode offering this? Is this specific to NSArray properties? What is the purpose of creating a method/getter for this method? If I don't define it manually, will it be automatically created/synthesized?

推荐答案

这是对索引集合(可在您的类中使用)进行了很少使用的KVC优化的结果.您可以在此处上阅读.,但摘录:

This is the result of a little-used KVC optimization for indexed collections which can be used on your class. You can read about this here, but to excerpt:

索引到多对关系合规性

Indexed To-Many Relationship Compliance

对于建立索引的多对多关系,符合KVC要求您的课程:

For indexed to-many relationships, KVC compliance requires that your class:

  • 实现一个名为-< key> 的方法,该方法返回一个数组.
  • 或者有一个名为< key> _< key> 的数组实例变量.
  • 或实现方法 -countOf< Key> 和-objectInAtIndex:或-< key> AtIndexes:中的一个或两个.
  • (可选)您还可以实现 -get< Key>:range:以提高性能.
  • Implement a method named -<key> that returns an array.
  • Or have an array instance variable named <key> or _<key>.
  • Or implement the method -countOf<Key> and one or both of -objectInAtIndex: or -<key>AtIndexes:.
  • Optionally, you can also implement -get<Key>:range: to improve performance.

它仅与带有KVC(有时为 NSPredicate s)的Core Data一起真正使用,但是您可以根据需要利用这些方法.

It's only really used with Core Data with KVC (and occasionally NSPredicates), but you can leverage these methods if you'd like to.

在99%的情况下,实现这一点实际上不是必需的,但是如果您愿意,也可以.

It's really not necessary in 99% of cases to implement this, but you can if you'd like.

这篇关于Xcode自动完成功能会提示神秘的&amp;"songsAtIndexes&amp;"用于NSArray吸气剂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆