Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When accessing app group lots of errors about optionals #24

Open
poml88 opened this issue Aug 31, 2024 · 1 comment
Open

When accessing app group lots of errors about optionals #24

poml88 opened this issue Aug 31, 2024 · 1 comment

Comments

@poml88
Copy link

poml88 commented Aug 31, 2024

Hi, if I use this code in Xcode 15

let sdefaults = SecureDefaults(suiteName: "a")
        if !sdefaults.isKeyCreated {
            sdefaults.password = UUID().uuidString
        }
        sdefaults.set(password, forKey: "libre-direct.settings.password")
        sdefaults.synchronize()

I get quite some errors about optionals:

Value of optional type 'SecureDefaults?' must be unwrapped to refer to member 'isKeyCreated' of wrapped base type 'SecureDefaults'
Value of optional type 'SecureDefaults?' must be unwrapped to refer to member 'password' of wrapped base type 'SecureDefaults'
Value of optional type 'SecureDefaults?' must be unwrapped to refer to member 'set' of wrapped base type 'SecureDefaults'
Value of optional type 'SecureDefaults?' must be unwrapped to refer to member 'synchronize' of wrapped base type 'SecureDefaults'

@poml88
Copy link
Author

poml88 commented Aug 31, 2024

When I use this extension:

extension SecureDefaults {
    static let sgroup = SecureDefaults(suiteName: stringSValue(forKey: "APP_GROUP_ID"))!
    
    static func stringSValue(forKey key: String) -> String {
        guard let value = Bundle.main.object(forInfoDictionaryKey: key) as? String else {
            fatalError("Invalid value or undefined key")
        }
        return value
    }
}

it does work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant