Skip to content

Instantly share code, notes, and snippets.

@mattjgalloway
Last active September 26, 2016 06:32
Show Gist options
  • Save mattjgalloway/6b46ae89f6603cdd64c49f38e07221b5 to your computer and use it in GitHub Desktop.
Save mattjgalloway/6b46ae89f6603cdd64c49f38e07221b5 to your computer and use it in GitHub Desktop.
WTF Swift
/**
* I have a URL and a UUID stored in UserDefaults, both as String.
* I want to extract both and convert the UUID string into an actual UUID.
* Here is something strange...
*/
// This works on iOS. But on watchOS, the guard returns, even though the URL and UUID exist in UserDefaults
guard
let accountURL = UserDefaults.standard.string(forKey: UserDefaultKeys.accountURL.rawValue),
let accountUUIDString = UserDefaults.standard.string(forKey: UserDefaultKeys.accountUUID.rawValue),
let accountUUID = UUID(uuidString: accountUUIDString),
else { return }
// However, in the following, on watchOS, the guard does pass.
guard
let accountURL = UserDefaults.standard.string(forKey: UserDefaultKeys.accountURL.rawValue),
1 == 1,
let accountUUIDString = UserDefaults.standard.string(forKey: UserDefaultKeys.accountUUID.rawValue),
1 == 1,
let accountUUID = UUID(uuidString: accountUUIDString),
1 == 1
else { return }
// WAT!?!!!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment