iPhone - setValue:forkey: 未记录
我的代码中有这些行:
[defaults setValue:someValue forKey:@"someValue"];
[animationGroup setValue:@"someValue" forKey:@"someValue"]; // CAAnimationGroup
NSString* animName = [theAnimation valueForKey:@"someValue"]; // CAAnimation
但是阅读Apple参考文档:
- https://developer.apple.com/library/IOs/#documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/Reference/Reference.html
- https://developer.apple.com/library/IOs/#documentation/GraphicsImaging/Reference/CAAnimationGroup_class/Introduction/Introduction.html
- https://developer.apple.com/library/IOs/#documentation/GraphicsImaging/Reference/CAAnimation_class/Introduction/Introduction.html#//apple_ref/occ/cl/CAAnimation
我不知道没有看到任何对这些方法的引用,甚至解析层次结构或一致的协议。他们从哪里来?允许使用它们吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(2)
情丝乱 2025-01-10 22:32:35
作为一个旁注,也让我感到困惑。上述链接之一提供:
CALayer和CAAnimation都是键值编码兼容的容器
类,允许您为任意键设置值。也就是说,同时
键“someKey”不是 CALayer 类的声明属性,
但是您仍然可以为键“someKey”设置一个值
这意味着您可以安全地发送类似 KVC 的 setValue:forKey: 和 valueForKey: 消息,而不必担心 @“someKey” 不是真正的 KVC 兼容的事实属性(因此是“任意键”)。如果您在其他对象上尝试此操作,可能会引发异常。我承认我不确定如何轻松找出其他类是否有这种行为,在许多其他地方免费提供这种行为肯定会很有用。
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
这些是键值编码方法;如果这些类符合这些键的键值编码,那么您可以毫无问题地使用它们。对于 Core Animation,
CALayer
和CAAnimation
均符合 KVC,详细信息请参见 本编程指南。有关更多一般信息,请参阅NSKeyValueCoding
非正式协议和 键值编码编程指南。These are Key-Value Coding methods; if those classes are Key-Value Coding compliant for those keys, then you can use them without issue. With respect to Core Animation, both
CALayer
andCAAnimation
are KVC compliant, as detailed in this programming guide. For more general information, refer to theNSKeyValueCoding
informal protocol and the Key-Value Coding Programming Guide.