Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import Foundation
class MyClass {
private let name: String
init(name: String) { = 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 }
Copy link

dohoan259 commented Jun 26, 2019

Good gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment