Skip to main content
added 304 characters in body
Source Link
Ahmad F
  • 31.8k
  • 19
  • 101
  • 151

You would need to declare a separated class for the location to contain the lat and the lng properties:

class Location: Mappable {
    var lat: Double?
    var lng: Double?
    
    required init?(map: Map){ }
    
    func mapping(map: Map) {
        lat <- map["lat"]
        lng <- map["lng"]
    }
}

thus you could use it as:

class Base: Mappable {
    var location: Location?
    // ...
    
    required init?(map: Map){ }
    
    func mapping(map: Map) {
        location <- map["location"]
        //...
    }
}

It would represent a nested type for mapping the base object.


Aside bar note: you might also want to check Codable - Encoding and Decoding Custom Types.

You would need to declare a separated class for the location to contain the lat and the lng properties:

class Location: Mappable {
    var lat: Double?
    var lng: Double?
    
    required init?(map: Map){ }
    
    func mapping(map: Map) {
        lat <- map["lat"]
        lng <- map["lng"]
    }
}

thus you could use it as:

class Base: Mappable {
    var location: Location?
    // ...
    
    required init?(map: Map){ }
    
    func mapping(map: Map) {
        location <- map["location"]
        //...
    }
}

It would represent a nested type for mapping the base object.

You would need to declare a separated class for the location to contain the lat and the lng properties:

class Location: Mappable {
    var lat: Double?
    var lng: Double?
    
    required init?(map: Map){ }
    
    func mapping(map: Map) {
        lat <- map["lat"]
        lng <- map["lng"]
    }
}

thus you could use it as:

class Base: Mappable {
    var location: Location?
    // ...
    
    required init?(map: Map){ }
    
    func mapping(map: Map) {
        location <- map["location"]
        //...
    }
}

It would represent a nested type for mapping the base object.


Aside bar note: you might also want to check Codable - Encoding and Decoding Custom Types.

added 59 characters in body
Source Link
Ahmad F
  • 31.8k
  • 19
  • 101
  • 151

You would need to declare a separated class for the location to contain the lat and the lng properties:

class Location: Mappable {
    var lat: Double?
    var lng: Double?
    
    required init?(map: Map){ }
    
    func mapping(map: Map) {
        lat <- map["lat"]
        lng <- map["lng"]
    }
}

thus you could use it as:

class Base: Mappable {
    var location: Location?
    // ...
    
    required init?(map: Map){ }
    
    func mapping(map: Map) {
        location <- map["location"]
        //...
    }
}

It would represent a nested type for mapping the base object.

You would need to declare a separated class for the location to contain the lat and the lng properties:

class Location: Mappable {
    var lat: Double?
    var lng: Double?
    
    required init?(map: Map){ }
    
    func mapping(map: Map) {
        lat <- map["lat"]
        lng <- map["lng"]
    }
}

thus you could use it as:

class Base: Mappable {
    var location: Location?
    // ...
    
    required init?(map: Map){ }
    
    func mapping(map: Map) {
        location <- map["location"]
        //...
    }
}

You would need to declare a separated class for the location to contain the lat and the lng properties:

class Location: Mappable {
    var lat: Double?
    var lng: Double?
    
    required init?(map: Map){ }
    
    func mapping(map: Map) {
        lat <- map["lat"]
        lng <- map["lng"]
    }
}

thus you could use it as:

class Base: Mappable {
    var location: Location?
    // ...
    
    required init?(map: Map){ }
    
    func mapping(map: Map) {
        location <- map["location"]
        //...
    }
}

It would represent a nested type for mapping the base object.

Source Link
Ahmad F
  • 31.8k
  • 19
  • 101
  • 151

You would need to declare a separated class for the location to contain the lat and the lng properties:

class Location: Mappable {
    var lat: Double?
    var lng: Double?
    
    required init?(map: Map){ }
    
    func mapping(map: Map) {
        lat <- map["lat"]
        lng <- map["lng"]
    }
}

thus you could use it as:

class Base: Mappable {
    var location: Location?
    // ...
    
    required init?(map: Map){ }
    
    func mapping(map: Map) {
        location <- map["location"]
        //...
    }
}