Objective-C中的@dynamic做什么? [英] What does @dynamic do in Objective-C?

查看:139
本文介绍了Objective-C中的@dynamic做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



Google只会列出有关动态打字的结果。



我很少在代码中看到这个,我不明白它用于什么。有人可以解释一下吗谢谢。

解决方案

@dynamic 意思是我的班级会弄清楚在运行时响应这一点。使用运行时机制来对象拦截通常不会响应的消息。在使用Core Data db存储持久性数据的情况下,NSManagedObject将其转换为调用 -valueForKey: -setValueForKey:



看看讲座12 (2010年秋季)斯坦福大学的iPhone开发课程。


Objective-C has a feature called @dynamic.

Google only lists results about dynamic typing.

I rarely see this in code and I don't understand what it is used for. Can anyone explain me this? Thanks.

解决方案

@dynamic means "my class will figure out how to respond to this at runtime." Uses a runtime mechanism for an object to intercept messages it normally wouldn’t respond to. In the case where a Core Data db is used to store persistent data, NSManagedObject turns these into calls to -valueForKey: and -setValueForKey:.

Take a look at Lecture 12 (Fall 2010) of Stanford's iPhone development course.

这篇关于Objective-C中的@dynamic做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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