Created
June 26, 2019 06:23
-
-
Save stansidel/938093b99fa0a888cc430efdf83742b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class MyClass { | |
private let name: String | |
init(name: String) { | |
self.name = name | |
} | |
// Pure computed property, cannot be set. Behaves like a constant field for the user of the class | |
var computed: String { | |
return "My name is \(name)" | |
} | |
// Property with getter only. Much like a computed property, defined with another syntax | |
var gettable: String { | |
get { | |
return "Gettable from name \(name)" | |
} | |
} | |
// Property with both getter and setter. Usually works as a proxy to other object's property. Or to control what's being set | |
private var _prop: String? | |
var prop: String { | |
get { return _prop ?? "" } | |
set { _prop = newValue } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good gist