Reputation: 79
I'm learning Objective C to program on iOS.
I know it has something to do with pointers, which I fail to understand.
I don't know what's the difference of creating a string (or any NSObject
) like this:
NSString place = ...;
or
NSString *place = ...;
Thanks for the help!!
Upvotes: 1
Views: 266
Reputation: 6831
Objective-C is, in some sense, more like a scripting language. Class definitions are maintained during runtime and can be modified. There is a C interface to the class definition system in objc.h. Even system classes can be modified, though it is not a good idea to do so. Because of this, all Objective-C objects must be created at runtime and accessed via pointers. To put it another way, there is no way for the compiler to know what an object should look like at compile time. This is also why "object may not respond to selector" is a warning, not an error and has the word "may" in it.
Upvotes: 1
Reputation: 185681
You never write NSString str
. Period. All Obj-C objects are actually C pointers.
Upvotes: 14
Reputation: 46965
NSString is a class and as such instances of the class declared as NSString *str
must always be declared as a pointer (since object instances can only be accessed via a pointer to the objects structure). Therefore this declaration is illegal: NSString str
Upvotes: 5