lachlanbell / SwiftOTP

A Swift library for generating One Time Passwords (OTP)
MIT License
285 stars 59 forks source link

Type of expression is ambiguous without more context #30

Closed nachoperez714 closed 2 years ago

nachoperez714 commented 2 years ago

I just try this

TOTP(secret: getUser()?.secret, digits: 6, timeInterval: 30, algorithm: .sha1)

And swift hits me with

Type of expression is ambiguous without more context

Am i missing something? I was following the readme

lachlanbell commented 2 years ago

Hi @nachoperez714,

This is probably due to the fact that getUser() is returning an optional value, and the secret: parameter only takes non-optional arguments.

Try something like this:

// Unwrap the optional value first
if let user = getUser() {
    totp = TOTP(secret: user, digits: 6, timeInterval: 30, algorithm: .sha1)
}