티스토리 뷰

모바일/iOS

property attributes (nonatomic, copy, strong, weak)

VoidNoble 공허공자 2014. 2. 24. 17:26

http://stackoverflow.com/a/9860283

Nonatomic

nonatomic은 다중 threading 목적들에 사용된다. If we have set the nonatomic attribute at the time of declaration, then any other thread wanting access to that object can access it and give results in respect to multi-threading.

Copy

copy는 object가 가변적일때 사용된다. Use this if you need the value of the object as it is at this moment, and you don't want that value to reflect any changes made by other owners of the object. You will need to release the object when you are finished with it because you are retaining the copy.

Assign

Assign은 다소 copy와 반대다. When calling the getter of an assign property, it returns a reference to the actual data. Typically you use this attribute when you have a property of primitive type (float, int, BOOL...)

Retain

retain은 attribute가 object에 포인터일때 필요. The setter generated by @synthesize will retain (aka add a retain count to) the object. You will need to release the object when you are finished with it. By using retain it will increase the retain count and occupy memory in autorelease pool.

Strong

strong은 retain attribute 대신인데, Objective-C Automated Reference Counting (ARC)의 부분으로. ARC 아닌 code 에서는 단지 retain의 동의어일 뿐.

iOS strong 과 weak 배우기위한 좋은 사이트는 아래의 링크로
http://www.raywenderlich.com/5677/beginning-arc-in-ios-5-part-1

Weak

weak은 strong과 유사하나 참조 카운트를 1 이상 증가시키지 않을것이다. It does not become an owner of that object but just holds a reference to it. If the object's reference count drops to 0, even though you may still be pointing to it here, it will be deallocated from memory.

위 링크는 Weak and Strong 관련한 좋은 정보들을 포함하고 있다.

댓글
댓글쓰기 폼
Total
818,296
Today
119
Yesterday
305
«   2020/02   »
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
글 보관함