class PostTilesTransform: TransformType {
typealias Object = [Tile]
public init() {}
public func transformFromJSON(_ value: Any?) -> [Tile]? {
print(value.debugDescription) // I want to see the whole JSON data
print(type(of: value!)) // I want to see JSON data type's name
return []
}
public func transformToJSON(_ value: [Tile]?) -> JSON? {
return nil
}
}
struct Post: Mappable {
var uuid: String = ""
var title: String = "No title"
var tiles: [Tile] = []
init?(map: Map) {}
// Mappable
mutating func mapping(map: Map) {
uuid <- map["uuid"]
title <- map["title"]
tiles <- (map, PostTilesTransform())
}
}
What you did:
let repo = Mapper<Post>().map(myJSONDictionary)
What you expected:
I exepected something like:
public func transformFromJSON(_ value: Any?) -> [Tile]? {
print(value.debugDescription) // I want to see the whole JSON data
print(type(of: value!)) // I want to see JSON data type
return []
}
What you got:
public func transformFromJSON(_ value: Any?) -> [Tile]? {
print(value.debugDescription) // This prints title - `TITLE`
print(type(of: value!)) // This prints String type's name
return []
}
So this means that following line sends only title, not whole data.
I want to send whole JSON data to custom transform. But it sends only one property(
title
in my example code). How can I send the whole data?Your JSON dictionary:
Your model:
What you did:
What you expected:
I exepected something like:
What you got:
So this means that following line sends only
title
, not whole data.