Timmy T Timmy T - 1 year ago 98
iOS Question

Swift 3: Instance member 'CognitoPoolID' cannot be used on type 'Constants'

I haven't been able to solve this problem on Xcode.

Here is how the Constants are defined

struct Constants {

let CognitoRoleAuth = "arn:aws:iam::XXXXXXXXXXXX:XXXX/XXXXXXX_XXXXXXXX_XXXX"


The main problem is on this line

let provider = AWSCognitoCredentialsProvider(...

The error that I receive when I try to build and/or run a code analysis gives me the following compiler error.

Instance member 'CognitoPoolID' cannot be used on type 'Constants'

Here is the code from the provider declaration all the way down to the end.

// This specifies AWS connection parameters.
let provider = AWSCognitoCredentialsProvider (regionType: .apNortheast1,
identityPoolId: Constants.CognitoPoolID.value,
authRoleArn: Constants.CognitoRoleAuth.value,
identityProviderManager: Constants.AWSAccountID.value);

let configuration = AWSServiceConfiguration(region:.apNortheast1, credentialsProvider:provider);


// Set out the Auth0 URL here which is the same Open ID Connect Provider URL.
provider.logins = ["marcadian.au.auth0.com" : idToken]

provider.getIdentityId().continue({ (task:AWSTask!) -> Any? in


if (task.error != nil) {
// Failed Error Handling code goes here.

} else {
// User has logged in successfully.

return nil

// User has dismissed the Lock View Controller.
controller?.dismiss(animated: true, completion: nil)


What does this mean?

Answer Source

The error message Instance member 'CognitoPoolID' cannot be used on type 'Constants' means that you are applying CognitoPoolID to the name of a class or struct, Constants, but it is an instance property. If you meant this to be a class or static property, you needed to declare it with class or static.

So, in your case, you have said:

struct Constants {
    let AWSAccountID = // ...
    let CognitoPoolID = // ...
    let CognitoRoleAuth = // ...

You should have said:

struct Constants {
    static let AWSAccountID = // ...
    static let CognitoPoolID = // ...
    static let CognitoRoleAuth = // ...

Just make that change. Now your code will compile (and work) correctly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download