What is the meaning of non-atomic and stored in the declaration of property

I am new to iOS programming. Can someone tell me the exact meaning of the next line of code @property(**nonatomic, retain**) UIView *singleTapView;

I used @property many times, actually knowing the exact meaning of the function (nonatomic, retain or assign or copy). Can anyone help me with this. Thankyou

+3
source share
5 answers

Properties are used in iOS to replace the getter and setter methods that we usually write.

Your line of code:

@property ( non- atomic , save ) UIView * singleTapView;

means you are writing getter and setter methods for your UIView.

UIView, .

, :

@property (, ) UIView * singleTapView;

UIView, . , UIView.

"copy" , .

+4

, .

@property - . .


nonatomic , @synthesize , . , atomic, .. .

( atomic), @synthesized , / . Apple docs, , , /.

, . .


. , , ,

alloc β†’ init β†’ retain β†’ release

. , , , .

+9
+4

@property, getter setter ....

, , @property

@property(nonatomic,retain) setter, , ...

, self.variableName, setter, @property

+1

For the non-atomic / atomic part, you should read the Atomic Operation . This does not apply to iOS, but will give you a better understanding.

For the part, saving this code will help you. This is similar to what @synthesizewill generate for you

//getter
- (Book *)book
{
    return [[book retain] autorelease];
}

//setter
- (void)setBook:(Book *)aBook
{
    if (book == aBook)
    {
        return;
    }
    Book *oldBook = book;
    book = [aBook retain];
    [oldBook release];
}
+1
source

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


All Articles