Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
469 views
in Technique[技术] by (71.8m points)

cocoa touch - What are the default attributes for Objective-C properties?

What are the default attributes for a properpty when you do not list any in objective C?

Such as for example if I wrote this:

@property float value;

What would the defaults be, like is it read only, does it retain...etc.?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The default/implicit values are atomic, readwrite, and assign.

atomic

This means that the value is read/written atomically. Contrary to the somewhat popular misconception, atomicity does not equate to thread safety. In simple terms, it guarantees that the value you read or write will be read or written in whole (when the accessors are used). Even when you use accessors all the time, it's not strictly thread safe.

readwrite

The property is given a setter and a getter.

assign

This default is usually seen used for POD (Plain-Old-Data) and builtin types (e.g. int).

For NSObject types, you will favor holding a strong reference. In the majority of cases, you will declare the property copy, strong, or retain. assign performs no reference count operations. See also: http://clang.llvm.org/docs/AutomaticReferenceCounting.html#property-declarations

strong

The property may be implicitly strong under ARC in some cases:

A property of retainable object pointer type which is synthesized without a source of ownership has the ownership of its associated instance variable, if it already exists; otherwise, [beginning Apple 3.1, LLVM 3.1] its ownership is implicitly strong. Prior to this revision, it was ill-formed to synthesize such a property.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...