我在Alamofire中使用AlamofireObjectMaper获取我的分类对象数组时遇到问题
我的对象:
import Foundation
import ObjectMapper
class Category: Mappable {
public var iDCategory: Int?
public var nameCategory: String?
public var img: String?
func mapping(map: Map) {
iDCategory <- map["IDCategory"]
nameCategory <- map["NameCategory"]
img <- map["img"]
}
required init?(map: Map) {
}
}
和我的电话:
import Foundation
import UIKit
import Alamofire
class ControllerSearch: UIViewController {
override func viewDidLoad() {
Alamofire.request("http://pazirandegan.farhadarghavan.ir/api/ApiCategory")
.responseArray { (response: DataResponse<[Category]>) in
for a in response.value!{
print(a.nameCategory!)
}
}
}
}
JsonArray:
[{"IDCategory":2,"NameCategory":"رستوران و کافه","img":"/Upload/Images/eb0c3cd1-d911-43bb-bf59-9b736a98c49e.PNG"},{"IDCategory":3,"NameCategory":"پوشاک و البسه","img":"/Upload/Images/5da2b69a-3063-4b34-a74b-64ba8fb166c6.jpg"},{"IDCategory":4,"NameCategory":"پزشکی و سلامت","img":"/Upload/Images/a8bb9506-7c31-4ed0-b05b-41d9a760ab43.jpg"},{"IDCategory":5,"NameCategory":"فروشگاه و زنجیره ای","img":null},{"IDCategory":6,"NameCategory":"لوازم خانگی","img":null},{"IDCategory":7,"NameCategory":"زیبایی","img":null},{"IDCategory":8,"NameCategory":"فرهنگ و هنر","img":"/Upload/Images/43958739-0f41-489f-882c-65c2e2fd6eb1.jpg"},{"IDCategory":9,"NameCategory":"خودرو","img":null},{"IDCategory":10,"NameCategory":"کالای دیجیتال","img":null}]
没有错误,输出完美,但我的应用程序崩溃
注意:使用Alamofire responseString
时一切正常。
问题是什么。