Snippets Collections
Make sure to add encodable like this 

struct modelName : Encodsble

let categories = categoriesArray.map{ $0.toDictionary()  }

extension Encodable {
    func toDictionary() -> [String: Any] {
        let mirror = Mirror(reflecting: self)
        var dictionary = [String: Any]()
        for child in mirror.children {
            guard let label = child.label else {
                continue
            }
            dictionary[label] = child.value
        }
        return dictionary
    }
}
star

Fri Jun 23 2023 08:10:31 GMT+0000 (Coordinated Universal Time)

#ios #swift #dic #dict #model #modelarray #dictonary

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension