Search code examples
iosjsonswiftgeojson

Swift 3 - Error 'Contextual type 'AnyObject' cannot be used with dictionary literal'


I have downloaded the 'GeoJSON' pod via Cocoapods. But when I try to run my app I recieve following error.

Error: Contextual type 'AnyObject' cannot be used with dictionary literal. (Image)

public var dictionaryRepresentation: [String: Any] {
        return [
            "geometry": [
                "coordinates": self.geometryCoordinates,
                "type": type(of: self).type
            ],
            "type": "Feature",
            "properties": [:]
        ]
    }

Solution

  • I solved it like this

    public var dictionaryRepresentation: [String: Any] {
            return [
                "geometry": [
                    "coordinates": self.geometryCoordinates,
                    "type": Self.type
                ] as [String: Any],
                "type": "Feature",
                "properties": [:]
            ]
        }