IOS - Is it better to use getter / setter methods directly or properties

I know that type properties encapsulate the getter and setter methods. Therefore, when we say myObject.property1, we actually call the [myObject property1] call. From Apple documentation, Stanford iOS courses, and model codes, I see that the use of properties is encouraged. I claim that using properties makes the code better and clearer, but what about performance? If I write a huge application, will using properties have a noticeable effect on performance? Do professionals always prefer the direct methods and properties of a utilizer and getter?

+4
source share
5 answers

There is no difference in performance if you use the bracket notation ( [myObject property1] ) or the notation . ( myObject.property1 ).

This is more of a coding style than any other thing, so use a notation that is more convenient for you, or the same notation as your team if you are not working alone.

+3
source

Properties are probably better because they automatically generate methods for you, and when you synthesize them, you can do it like this:

 @synthesize property = _property 

To avoid confusion

You can also select various functions / methods, for example:

  (nonatomic, retain) // or (readonly) etc. 

It also handles memory better.

+2
source

Properties are certainly preferred. This, by the way, is the @synthesize operator, which generates getters and setters automatically. There are no messages for me that would confirm performance changes with setters / getters.

+1
source

The property syntax translates directly to getter / setter calls. I have no idea that it takes longer to compile, or if there is a difference, but when the program runs, the code execution is the same.

+1
source

When you use declared properties, getter and setter are generated at compile time, so the performance impact does not affect the declaration of your activator and setter at all.

Wed http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html

+1
source

Source: https://habr.com/ru/post/1403879/


All Articles