You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Say we want write custom logic for a specific domain. For example: below, I have a UUID getter and setter.
We could add a nested enum/struct for AppUUID.
import KeychainAccess
finalclassKeychainHelper{// MARK: - Publicstaticfunc nxv_store(_ value:String, key:String){letkeychain=Keychain(service:"\(AppConfiguration.App.bundleID).\(key)")keychain[key]= value
}staticfunc nxv_valueForKey(_ key:String)->String{letkeychain=Keychain(service:"\(AppConfiguration.App.bundleID).\(key)")returnkeychain[key]??""}}extensionKeychainHelper{// MARK: - UUIDstructAppUUID{staticfunc generateAppUUIDandStore(){// only generate and store UUID on when we can't get UUID from keychain,// since we store it to keychain, so don't check for first launch
if isAppUUIDValid == false {KeychainHelper.nxv_store(UUID().uuidString, key:Constants.Keychain.savedAppUUID)}}staticvarappUUID:String{returnKeychainHelper.nxv_valueForKey(Constants.Keychain.savedAppUUID)}staticvarisAppUUIDValid:Bool{return appUUID.isEmpty == false
}}}
So in usage, it's better to know on glance which problem we are dealing from the helper
letappUUID=KeychainHelper.AppUUID.appUUID
// is, in my opinion, better thanletappUUID=KeychainHelper.appUUID
As we glance it, we could see that we are telling KeychainHelper, return me a generated appUUID from AppUUID domain.
We could just declare struct UUID, but thanks to Swift compiler warning, in the setter, we use Foundation's UUID class method UUIDString to generate a unique ID. So namespace collision happened there.
TIL
The text was updated successfully, but these errors were encountered:
Say we want write custom logic for a specific domain. For example: below, I have a UUID getter and setter.
We could add a nested enum/struct for AppUUID.
So in usage, it's better to know on glance which problem we are dealing from the helper
As we glance it, we could see that we are telling KeychainHelper, return me a generated appUUID from AppUUID domain.
We could just declare
struct UUID
, but thanks to Swift compiler warning, in the setter, we use Foundation's UUID class method UUIDString to generate a unique ID. So namespace collision happened there.TIL
The text was updated successfully, but these errors were encountered: