In objective-c whats the difference between using a . and using ->? I’ve used dot notation many times but have only just come across ->
E.G
Object.subObject
or
Object->subObject
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
myObject.myPropertyThe dot could either be calling a the getter/setter for a property or accessing a struct.
In your case subObject is probably not a struct so using
myObject.myPropertywould be the same as calling the method[myObject myProperty]which is the getter for the "myProperty" property.The same way when you are setting a new value using the dot. You are calling
[myObject setMyProperty:newValue];which will do the appropriate memory management defined for your property (like retain, copy or assign the value as well as release the old value).(Using getters and setters will also call the work with KVO)
myObject->myPropertyThe arrow is pointing to the memory of the variable.
This simply means that you are following the pointer that points to the memory where
myPropertyis located. This is lower level and does not do any memory management for you, nor does it work with KVO.