Search code examples
swifteureka-forms

Convert from NSDictionary to [String:Any?]


I am using xmartlabs/Eureka to build an app with a dynamic form.

In order to fill the form I have to use setValues(values: [String: Any?]).

But I have the form values in an NSDictionary variable and I cannot cast it to [String:Any?].

Is there a way to convert an NSDictionary to [String:Any?] ?


Solution

  • Hope this helps:

    let dict = NSDictionary()
    var anyDict = [String: Any?]()
    
    for (value, key) in dict {
        anyDict[key as! String] = value
    }