What's the difference between using obj-c accessors and using dot syntax?

What's the difference between using obj-c accessors and using dot syntax?

Since I've started on iPhone development I've been kinda confused as to which is the best way to access data as a member in a Class.

Let's say I have a class called MyClass, and in it I have:

@interface MyClass : NSObject {     int myInt; }  @property (nonatomic, assign) int myInt; 

In the implementation, is it better to do this:

myObject.myInt = 1; 

Or this?

[myObject setMyInt:1]; 

This goes for reading the value too.

int newInt = myObject.myInt; 


int newInt = [myObject myInt]; 

Best way to manage probably huge photo library with iPhone SDK


How make scrolling function with Interface builder on the iPhone?
It doesn't really matter, they are the same thing. How programatically move a UIScrollView to focus in a control above keyboard?The dot syntax is a convenience that's there for you to use, and I feel like it makes your code cleaner.. How much of a transition is programming Java to iPhone apps? The one case where I find this using the dot syntax throws warning or errors from the compiler is if you have have an id object, even if you know it has this property.. Best client-side data store for iPhone web app?
id any ReturnedObject = [any thingObject any MysteryObjectAtIndex:5]; int aValue = 0; aValue = any ReturnedObject.value; // warning aValue = [any ReturnedObject value]; // will just did  it 
How return back info from a child to parent in a NavigationControllerDo you tag your UIViews or retain them as properties?


return value javascript UIWebView
The type of the object is statically checked with the . syntax, although not with the [] syntax. This means you can't use . if the object's type isn't specified, and this it is beneficial to use it when it is, so the compiler will guidance you more..


Dot syntax in Objective-C is essentially shorthand for using the accessor methods. The message is still sent via the accessor method. Hope this answers your question.

50 out of 100 based on 10 user ratings 330 reviews