Home > DeveloperSection > Forums > Performance difference between dot notation versus method call in Objective-C
Tarun Kumar

Total Post:214

Posted on    July-31-2015 11:57 PM

 iPhone iPhone  Ios  Objective C 

 1 Reply(s)
 816  View(s)
Rate this:

You can use a standard dot notation or a method call in Objective-C to access a property of an object in Objective-C.

myObject.property = YES;


[myObject setProperty:YES];

Is there a difference in performance (in terms of accessing the property)? Is it just a matter of preference in terms of coding style?

naomi burke
naomi burke

Total Post:28

Posted on    August-01-2015 12:04 AM

Dot notation for property access in Objective-C is a message send, just as bracket notation. That is, given this:

Foo *foo = [[Foo alloc] init];

foo.bar = YES;

@interface Foo : NSObject

@property BOOL bar;


Foo *foo = [[Foo alloc] init];

foo.bar = YES;

foo setBar:YES];

The last two lines will compile exactly the same. The only thing that changes this is if a property has a getter and/or setter attribute specified; however, all it does is change what message gets sent, not whether a message is sent:

@interface MyView : NSView

@property(getter=isEmpty) BOOL empty;


if ([someView isEmpty]) { /* ... */ }

if (someView.empty) { /* ... */ }

Both of the last two lines will compile identically.



Modified On Mar-18-2016 11:09:26 PM

Don't want to miss updates? Please click the below button!

Follow MindStick