Last active
October 26, 2019 09:46
-
-
Save nsoojin/1c77774279e1954de5ddec1d71ad84c1 to your computer and use it in GitHub Desktop.
LateInitialized Property Wrapper
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
@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 | |
} | |
set { | |
storage = newValue | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment