由于某些原因,我的序列化时间非常长。我使用Alamofire和ObjectMapper来处理请求响应并将数据反序列化为对象。
这是我发送的请求:
Alamofire.request(Constants.apiRequests.paloozas, method: .get, parameters: params, headers: HeaderManager.sharedInstance.authHeader!).validate().responseObject { (response: DataResponse<PaginatedPaloozas>)
// handle response
}
这是PaginatedPaloozas对象:
struct PaginatedPaloozas: Mappable {
var meta: PageMetaData?
var paloozas: [Palooza]?
init?(map: Map) { }
mutating func mapping(map: Map) {
self.meta <- map[Constants.PaginatedPaloozas.meta]
self.paloozas <- map[Constants.PaginatedPaloozas.paloozas]
}
}
这是我的Palooza对象:
struct Palooza: Mappable {
var id: Int!
var startingLocation: Place!
var endingLocation: Place!
var startTime: Date!
var endTime: Date?
var note: String?
var perPersonPrice: String!
var seats: Int!
var chat: String?
var completedAt: Date?
var numSeatsAvailable: Int!
var distance: Float?
var bookingFee: String!
var totalPrice: String!
var status: PaloozaStatus!
var code: String?
var involvement: Involvement!
var bookings: [Booking]?
var owner: Owner?
enum PaloozaStatus: String {
case pending = "pending"
case inProgress = "in_progress"
case cancelled = "cancelled"
case completed = "completed"
}
enum Involvement: String {
case owner = "owner"
case presenter = "presenter"
case none = "none"
}
init?(map: Map) { }
mutating func mapping(map: Map) {
self.id <- map[Constants.Palooza.id]
self.startingLocation <- map[Constants.Palooza.startingLocation]
self.endingLocation <- map[Constants.Palooza.endingLocation]
self.startTime <- (map[Constants.Palooza.startTime], CustomDateTransform())
self.endTime <- (map[Constants.Palooza.returnTime], CustomDateTransform())
self.note <- map[Constants.Palooza.note]
self.perPersonPrice <- map[Constants.Palooza.perPersonPrice]
self.seats <- map[Constants.Palooza.seats]
self.chat <- map[Constants.Palooza.chat]
self.completedAt <- (map[Constants.Palooza.completedAt], CustomDateTransform())
self.numSeatsAvailable <- map[Constants.Palooza.numSeatsAvailable]
self.distance <- map[Constants.Palooza.distance]
self.bookingFee <- map[Constants.Palooza.bookingFee]
self.totalPrice <- map[Constants.Palooza.totalPrice]
self.status <- (map[Constants.Palooza.status], EnumTransform<PaloozaStatus>())
self.code <- map[Constants.Palooza.code]
self.involvement <- (map[Constants.Palooza.involvement], EnumTransform<Involvement>())
self.bookings <- map[Constants.Palooza.bookings]
self.owner <- map[Constants.Palooza.owner]
}
}
我只有5个paloozas,它需要10秒才能序列化。我尝试在Alamofire请求中使用不同的队列,但它没有任何区别。请帮我加快这个过程。
答案 0 :(得分:1)
事实证明我正在减慢序列化过程,因为我试图在此过程中从URL获取UIImage。我希望这能帮助像我这样犯了愚蠢错误的其他人哈哈。
答案 1 :(得分:0)
I would already be about the connection and server problem if network speed is
slow. Try using a different endpoint from a different server to test the
speed.If its faster then the problem is on your server. Since your
implementation is correct then definitely it is server problem. alamofire has
nothing to do on handling the issue if the problem is on the server or
connection.