Skip to content

Instantly share code, notes, and snippets.

@vialyx
Last active October 11, 2018 03:50
Show Gist options
  • Save vialyx/75dfde49e20ed7849c2c66c56d03fa8f to your computer and use it in GitHub Desktop.
Save vialyx/75dfde49e20ed7849c2c66c56d03fa8f to your computer and use it in GitHub Desktop.
class TransportStorage {
var output: NSObject!
let database: Any // <----- Constant
var token: String?
init(database: Any) {
self.database = database
}
}
let storage = TransportStorage(database: UserDefaults.standard)
// Optional with case .none -> nil
storage.token?.description
// this triggers a runtime error
storage.token!.description
storage.token = UUID().uuidString
// Optional with case .some -> String
storage.token?.description
// *** Crash!!! The output in currently nil ***
// this triggers a runtime error
// storage.output.description
storage.output = NSObject()
// Output have with value. All work good
storage.output.description
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment