Swift property - getter ivar
问题 Is there an ivar property we should use in a Swift getter? My code is causing the getter to call the getter until the program crashes: var document: UIDocument? { get { return self.document } set { self.document = newValue useDocument() } } 回答1: Swift properties do not have the concept of separate, underlying storage like they do in Objective-C. Instead, you'll need to create a second (private) property and use that as the storage: private var _document: UIDocument? var document: UIDocument?