I have read "What's new in Xcode",but I can't find the official explanation for this feature. Where can I find the official explanation? Which documentation? Thanks.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Does JavaScript allow getters and setters?
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
Assuming you mean that it auto-generates an ivar and getter and setter methods for you even if you omit the
@synthesize
: this is variously called default property synthesis, automatic property synthesis, and property autosynthesis.There's not a lot of documentation. As far as I have found, there's no official documentation of how it works, just of the fact that it exists.
It's really a clang feature, not an Xcode feature. It appeared briefly in the version clang shipped with Xcode 4.0 DP 4, but was removed shortly after due to bugs. It reappeared in the version of clang shipped with Xcode 4.4. Here's the commit that added it, I think.
You can find it mentioned in the Objective-C Feature Availability Index.
It's also mentioned in the Clang Language Extensions.
From experimentation:
If you don't explicitly
@synthesize
a property and it generates an instance variable, it will automatically generate an ivar with the same type (and, under ARC, ownership qualification) as the declared property. The ivar name will be an underscore (_
) followed by the declared property name.If you don't explicitly
@synthesize
areadonly
property, and you do include an explicit getter method, then clang will not automatically generate an ivar for you.If you don't explicitly
@synthesize
areadwrite
property, and you do include both an explicit getter and an explicit setter, then again clang will not automatically generate an ivar for you.But I don't know of any official documentation of these behaviors.
You can find this in the Apple documentation in Objective-C Programming Language: Declared Properties under "Property Implementation Directives". Whether or not an ivar is synthesized automatically depends on what runtime you are using:
iOS always uses the modern runtime so you never need to declare ivars explicitly.
This is part of the compiler, actually.
You can read that in the
LLVM
specification website.I would also draw your attention to the Coding Guidelines for Cocoa which advises: