How can the following be working in Xcode Playground and not when running on device or emulator.
Alamofire is returning allright with everything. I can pass it with .responseJSON
no problem.
But using .responseObject
it fails here in line 74 with SIGABRT
And the console says: Message from debugger: Terminated due to signal 9
Again, this is working from Playground with same classes and Alamofire.request
Alamofire.request(
url_planday_employees,
method: .get,
headers: headers_employees).responseObject { (response: DataResponse<Items>) in
// Error
for item in (userResponse?.items)! {
if let user = item.user {
print("Result in... user")
print("Name:" + user.name! )
}
}
}
The Classes:
class User: Mappable {
var name: String?
var id: Int?
required init?(map: Map){}
func mapping(map: Map) {
name <- map["name"]
id <- map["id"]
}
}
class Item: Mappable {
var user: User?
required init?(map: Map){}
func mapping(map: Map) {
user <- map["item"]
}
}
class Items: Mappable {
var items: [Item]?
required init?(map: Map){}
func mapping(map: Map) {
items <- map["items"]
}
}
The JSON:
{
"items": [
{
"item": {
"id": 1,
"name": "Anders And"
}
},
{
"item": {
"id": 2,
"name": "Andersine"
}
}
]
}
It looks like the problem was about incompatibility issues between 2.2.1 and 2.2.2 of ObjectMapper library.
Here is the related issues opened a while ago:
For a quick fix, you can use the older version (2.2.1):
As for carthage here is how it is done:
github "Alamofire/Alamofire" ~> 4.3.0
github "tristanhimmelman/AlamofireObjectMapper" ~> 4.0.1
github "Hearst-DD/ObjectMapper" == 2.2.1
Update
As of version 2.2.3, problem seems to be fixed:
github "Hearst-DD/ObjectMapper" ~> 2.2.3