2

I'm working on Auth0 Lock integration, i'm getting error Use of unresolved identifier 'connections'; did you mean 'Connections'?.

.withConnections {_ in
  connections.database(name: "Username-Password-Authentication", requiresUsername: true)
}

I changed code to

Connections.database(name: "Username-Password-Authentication", requiresUsername: true) 

Now I'm getting error Instance member 'database' cannot be used on type 'Connections'

When I changed code to

Connections().database(name: "Username-Password-Authentication", requiresUsername: true)

Getting error 'Connections' cannot be constructed because it has no accessible initializers

I changed code to

$0.database(name: "Username-Password-Authentication", requiresUsername: true)

Getting Anonymous closure arguments cannot be used inside a closure that has explicit arguments

https://github.com/auth0/Lock.swift

https://auth0.com/docs/libraries/lock-ios/v2#configuration-options

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    Lock
        .classic()
        // withConnections, withOptions, withStyle, and so on
        .withOptions {
            $0.oidcConformant = true
            $0.scope = "openid profile"
        }
        .onAuth { credentials in
            // Let's save our credentials.accessToken value
        }
        .withConnections {_ in
            connections.database(name: "Username-Password-Authentication", requiresUsername: true)
        }
        .withStyle {
            $0.title = "Company LLC"
            $0.logo = LazyImage(name: "123.png")
            $0.primaryColor = UIColor(red: 0.6784, green: 0.5412, blue: 0.7333, alpha: 1.0)
        }
        .present(from: self)
Naresh
  • 16,698
  • 6
  • 112
  • 113

3 Answers3

2

It seems the Auth0 documentation is erroneous here. If you look at the Lock.swift source file you see that a ConnectionBuildable is passed as argument. You need to use this to build your connections.

Try this:

.withConnections { connections in
    connections.database(name: "Username-Password-Authentication", requiresUsername: true)
}

or the same thing using anonymous closure arguments:

.withConnections {
    $0.database(name: "Username-Password-Authentication", requiresUsername: true)
}
Rengers
  • 14,911
  • 1
  • 36
  • 54
  • It seems in this case the documentation from Auth0 is erroneous. If you want to learn more about closures, check out the Swift docs: https://docs.swift.org/swift-book/LanguageGuide/Closures.html – Rengers Jan 22 '19 at 10:04
  • have you any idea about Auth0 lock implementation in Swift. – Naresh Jan 22 '19 at 10:04
  • I have never used this framework in Swift, if that’s what you mean. – Rengers Jan 22 '19 at 10:07
2

The error is in the closure for .withConnections You are not naming a parameter by using _

Without parameter

.withConnections { _ in }

With a parameter

.withConnections { connections in { connections.database(name: "Username-Password-Authentication", requiresUsername: true) }

  • For sure, search in google hackingwithswift closures. The first link has a good overview. Sean Allen in youtube has another good explanation. And if you want to get in depth check Advance Swift from Paul Hudson. – Matthew Xavier Jacome Jan 22 '19 at 10:06
1

You get Use of unresolved identifier 'connections'; did you mean 'Connections'? because connections is not declared as closure parameters.

Try:

.withConnections { connections in
  connections.database(name: "Username-Password-Authentication", requiresUsername: true)
}

or if you want using anonymous argument, do not declare any parameter:

.withConnections { 
  $0.database(name: "Username-Password-Authentication", requiresUsername: true)
}
Johan Drevet
  • 225
  • 2
  • 8