Chris Hansen
Chris Hansen

Reputation: 8663

Swift Error: Consecutive statements on a line must be separated by ';'

let email = MUser.sharedInstance.getUserEmail()
let json = [
    "listIds": [""],
    "contacts": [{ "email" : "\(email)" }]
];

I'm getting the error Consecutive statements on a line must be separated by ';' when running the code above. What am I doing wrong?

Upvotes: 0

Views: 1812

Answers (1)

Amir.n3t
Amir.n3t

Reputation: 3439

The problem is the dictionary email: email where {, } are not recognised keywords You can define your json like this :

let json = [
    """
    "listIds": [""],
    "contacts": [ {"email" : "\(email)" }]
    """
];

or if you prefer to construct your dictionary in contacts with code, you could do something like below:

let json = [

    "listIds": [""],
    "contacts": [[ "email" : "\(email)" ]]
];

Upvotes: 2

Related Questions