Prettygeek
Prettygeek

Reputation: 2531

Swift dictionary empty after appending elements

I have simple class:

import Foundation
import MapKit

class OWMAPIManager {


    private var params = [String : AnyObject]()

    internal init(apiKey: String) {
        params["APPID"] = apiKey
    }
}

And I'm creating new object by this:

let weatherApi = OWMAPIManager(apiKey: "myApi key")

Problem is that after init method my array Dictionary is still empty. Can You tell me what is wrong?

Upvotes: 0

Views: 65

Answers (2)

Kostas Tsoleridis
Kostas Tsoleridis

Reputation: 924

make sure you have initialised your dictionary

Upvotes: 0

Tom el Safadi
Tom el Safadi

Reputation: 6786

As I can see you have to change the following line, I can't see everything so it is hard to guess but this might be the problem. Change that:

private var params: [String: AnyObject]?

Write me if that did it

If you remove the question mark, then it is non optional

Upvotes: 1

Related Questions