Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
making stuff

Soojin Ro nsoojin

:octocat:
making stuff
View GitHub Profile
@nsoojin
nsoojin / SharedKeychain.swift
Created Oct 26, 2019
SharedKeychain Property Wrapper
View SharedKeychain.swift
@propertyWrapper
struct SharedKeychain {
let key: String
var wrappedValue: String? {
get {
return Global.sharedKeychain[string: key]
}
set {
if let value = newValue {
@nsoojin
nsoojin / SharedDefaults.swift
Last active Oct 26, 2019
SharedDefaults Property Wrapper
View SharedDefaults.swift
@propertyWrapper
struct SharedDefault<T> {
let key: String
let defaultValue: T
var wrappedValue: T {
get {
UserDefaults.securityCard.object(forKey: key) as? T ?? defaultValue
}
set {
@nsoojin
nsoojin / LateInitialized.swift
Last active Oct 26, 2019
LateInitialized Property Wrapper
View LateInitialized.swift
@propertyWrapper
struct LateInitialized<T> {
var storage: T? = nil
var wrappedValue: T {
get {
guard let value = storage else {
fatalError("value has not been set!")
}
return value
@nsoojin
nsoojin / ClampedString.swift
Created Oct 26, 2019
ClampedString Property Wrapper
View ClampedString.swift
@propertyWrapper
struct ClampedString {
let max: Int
var value: String
init(wrappedValue: String, max: Int) {
value = wrappedValue
self.max = max
}