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

<pre><code>myObject.property = YES;
</code></pre>

<p>or</p>

<pre><code>[myObject setProperty:YES];
</code></pre>

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

[{'answer_id': 34688, 'author': 'Daniel Jennings', 'author_id': 3641, 'author_profile': 'https://Stackoverflow.com/users/3641', 'pm_score': 0, 'selected': False, 'text': "<p>As far as I've seen, there isn't a significant performance difference between the two. I'm reasonably certain that in most cases it will be 'compiled' down to the same code.</p>\n\n<p>If you're not sure, try writing a test application that does each method a million times or so, all the while timing how long it takes. That's the only way to be certain (although it may vary on different architecture.)</p>\n"}, {'answer_id': 34690, 'author': 'Misha M', 'author_id': 3467, 'author_profile': 'https://Stackoverflow.com/users/3467', 'pm_score': 3, 'selected': False, 'text': '<p>Check out <a href="http://www.cimgf.com/2008/07/08/a-case-against-dot-syntax/" rel="noreferrer">article from Cocoa is My Girlfriend</a>.  The gist of it, is that there is no performance penalty of using one over the other.</p>\n\n<p>However, the notation does make it more difficult to see what is happening with your variables and what your variables are.</p>\n'}, {'answer_id': 35636, 'author': 'Chris Hanson', 'author_id': 714, 'author_profile': 'https://Stackoverflow.com/users/714', 'pm_score': 5, 'selected': True, 'text': '<p>Dot notation for property access in Objective-C <strong>is</strong> a message send, just as bracket notation.  That is, given this:</p>\n\n<pre><code>@interface Foo : NSObject\n@property BOOL bar;\n@end\n\nFoo *foo = [[Foo alloc] init];\nfoo.bar = YES;\n[foo setBar:YES];\n</code></pre>\n\n<p>The last two lines will compile exactly the same.  The only thing that changes this is if a property has a <code>getter</code> and/or <code>setter</code> attribute specified; however, all it does is change what message gets sent, not whether a message is sent:</p>\n\n<pre><code>@interface MyView : NSView\n@property(getter=isEmpty) BOOL empty;\n@end\n\nif ([someView isEmpty]) { /* ... */ }\nif (someView.empty) { /* ... */ }\n</code></pre>\n\n<p>Both of the last two lines will compile identically.</p>\n'}, {'answer_id': 61913, 'author': 'Kendall Helmstetter Gelner', 'author_id': 6330, 'author_profile': 'https://Stackoverflow.com/users/6330', 'pm_score': 3, 'selected': False, 'text': "<p>The only time you'll see a performance difference is if you do not mark a property as &quot;nonatomic&quot;.  Then <code>@synthesize</code> will automatically add synchronization code around the setting of your property, keeping it thread safe - but slower to set and access.</p>\n<p>Thus mostly you probably want to define a property like:</p>\n<pre><code>@property (nonatomic, retain) NSString *myProp;\n</code></pre>\n<p>Personally I find the dot notation generally useful from the standpoint of you not having to think about writing correct setter methods, which is not completely trivial even for nonatomic setters because you must also remember to release the old value properly.  Using template code helps but you can always make mistakes and it's generally repetitious code that clutters up classes.</p>\n<p>A pattern to be aware of: if you define the setter yourself (instead of letting <code>@synthesize</code> create it) and start having other side effects of setting a value you should probably make the setter a normal method instead of calling using the property notation.</p>\n<p>Semantically using properties appears to be direct access to the actual value to the caller and anything that varies from that should thus be done via sending a message, not accessing a property (even though they are really both sending messages).</p>\n"}, {'answer_id': 77874, 'author': 'charles', 'author_id': 9900, 'author_profile': 'https://Stackoverflow.com/users/9900', 'pm_score': 0, 'selected': False, 'text': '<p>Also read this blog post on Cocoa with Love:</p>\n\n<p><a href="http://cocoawithlove.com/2008/06/speed-test-nsmanagedobject-objc-20.html" rel="nofollow noreferrer">http://cocoawithlove.com/2008/06/speed-test-nsmanagedobject-objc-20.html</a></p>\n\n<p>There the author compares the speed of custom accessor and dot notations for NSManagedObject, and finds no difference. However, KVC access (setValue:forKey:) appears to be about twice as slow.</p>\n'}]
['https://Stackoverflow.com/questions/34674', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1987/']