my journey of developing iOS app begins

来源:互联网 发布:nginx tomcat负载均衡 编辑:程序博客网 时间:2024/06/07 10:06
Objective-C has an important type called id
Is it safe?
It means “pointer to an object of unknown/unspecified” type.
id myObject;
Really allobject pointers (e.g. NSString *) are treated like id at runtime.
But at compile time, if you type something NSString *instead of id, the compiler can help you.
It can find bugs and suggest what methods would be appropriate to send to it, etc.
If you type something using id, the compiler can’t help very much because it doesn’t know much.
Figuring out the code to execute when a message is sent at runtimeis called “dynamic binding.”
Treating all object pointers as “pointer to unknown type” at runtime seems dangerous, right?
What stops you from sending a message to an object that it doesn’t understand?
Nothing. And your program crashes if you do so. Oh my, Objective-C programs must crash a lot!
Not really.
Because we mostly use static typing (e.g. NSString *) and the compiler is really smart.
0 0