swift的属性与变量- Stored Properties and Instance Variables

是一个概念

Stored Properties and Instance Variables

If you have experience with Objective-C, you may know that it provides two ways to store values and references as part of a class instance. In addition to properties, you can use instance variables as a backing store for the values stored in a property.

Swift unifies these concepts into a single property declaration. A Swift property does not have a corresponding instance variable, and the backing store for a property is not accessed directly. This approach avoids confusion about how the value is accessed in different contexts and simplifies the property’s declaration into a single, definitive statement. All information about the property—including its name, type, and memory management characteristics—is defined in a single location as part of the type’s definition.

https://docs.swift.org/swift-book/LanguageGuide/Properties.html

猜你喜欢

转载自www.cnblogs.com/feng9exe/p/9145811.html