Skip to content

Instantly share code, notes, and snippets.

@KaneCheshire
Last active May 31, 2018 15:22
Show Gist options
  • Save KaneCheshire/cebcab6763097323501cb92f306bc733 to your computer and use it in GitHub Desktop.
Save KaneCheshire/cebcab6763097323501cb92f306bc733 to your computer and use it in GitHub Desktop.
import RealmSwift
class Settings: Object {
@objc private dynamic var _prefersFahrenheit: Bool = false // Realm requires all properties have a default value
var prefersFahrenheit: Bool { // I find it's best to define explicit getters and setters since you can transform primitives into enums etc.
get {
return _prefersFahrenheit
}
set {
try? realm?.write { // Realm objects have a Realm reference if they've been added to a Realm.
_prefersFahrenheit = newValue
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment