Why do I need to use the @property keyword in objective-c?

Suppose I have the following public methods in my class:

- (BOOL)finished
{
    return _finished;
}
- (void)setFinished:(BOOL)aValue
{
    _finished = aValue;
}

I also need to set the finished as a property in the class:

@property SomeClass *finished;

I may have misunderstood @property, but it seems to me that I am repeating myself.

  • Should declare both methods and @propertyor only one of them?
+4
source share
2 answers

By declaring a @property, the LLVM compiler automatically synthesizes your accessor methods (getter and setter), as well as the instance variable ( ivar), indicated by the underscore prefix ( _finished, for example)

, ( / ivar), @property . -finished -setFinished

@property, ivar

@property , - , , @Sulthan , @properties,

, @property atomic, ivar ,

+6

, , .

. @property . . . . ( , .)

, , , @synthesize .

, @synthesize @property. ( !)

. @property, ivar, . , "" ( ).

. , @property: . ( -setFinished:? -isFinished? -finished), (weak, strong, copy). , .

+2

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


All Articles