我即将使用 AlamofireObjectMapper 扩展来映射来自服务器的 JSON 响应并创建一个函数来返回对象
我写了这些代码func
func downloadPokemonDetails1(completed: DownloadComplete)-> (Pokemon?) {
let url = NSURL(string: _pokemonUrl)!
Alamofire.request(.GET, url).responseObject { (response: Response<Pokemon, NSError>) in
guard response.result.isSuccess else {
print(response.result.error.debugDescription)
return
}
let pokemon1 = response.result.value
return pokemon1
}
}
Herer是我的Constanst.swift(包含DownloadComplete
关闭)
import Foundation
let URL_BASE = "http://pokeapi.co"
let URL_POKEMON = "/api/v1/pokemon/"
typealias DownloadComplete = () -> ()
我不知道为什么 funcdownloadPokemonDetails1
给出错误un-expected Non-void return value in void function
我的Pokemon
班级
lass Pokemon: Mappable {
var id: String?
var name: String?
required init?(_ map: Map){
}
func mapping(map: Map) {
name <- map["name"]
id <- map["id"]
}
}