如何在请求后获取用户对象

时间:2015-10-07 13:13:03

标签: ios swift alamofire

我尝试实施Alamofire给出的示例:https://github.com/Alamofire/Alamofire#generic-response-object-serialization

问题是我想在请求之后获取完成处理程序的用户对象:

Alamofire.request(.GET, "https://example.com/users/mattt")
         .responseObject { (response: Response<User, NSError>) in
             debugPrint(response)
         }

有人知道如何从响应中访问用户对象吗?

1 个答案:

答案 0 :(得分:1)

您可以使用User类似:

访问response.result.value!对象
   Alamofire.request(.GET, "https://example.com/users/mattt")
     .responseObject { (response: Response<User, NSError>) in
         debugPrint(response)
        print(response.result.value!.username) //It will print username if `username` key belongs to your User object.
     }

希望这会有所帮助!