我刚接触swift,我不明白为什么我即使使用了`do catch`处理,仍然会出现这个错误。
我已经阅读了类似的问题,到目前为止,没有一个解决这个错误:
fetch方法:
它使用 Alamofire 和 AlamofireObjectMapper。你能看出我缺少了什么吗?
感谢任何帮助。
我已经阅读了类似的问题,到目前为止,没有一个解决这个错误:
在该行出错:Invalid conversion from throwing function type '(_) throws -> (). to non-throwing function type '([BeaconModel]) -> ()'
BeaconModel.fetchBeaconsFromRestApi(completionHandler: { .....
出错的代码片段:do{
let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
let db = try Connection("\(path)/db.sqlite3")
let beaconsTbl = Table("beacons")
let id = Expression<Int64>("id")
let uuid = Expression<String>("uuid")
let major = Expression<String>("major")
let minor = Expression<String>("minor")
try db.run(beaconsTbl.create { t in
t.column(id, primaryKey: true)
t.column(uuid)
t.column(major)
t.column(minor)
})
BeaconModel.fetchBeaconsFromRestApi(completionHandler: {
beacons in
for item in beacons{
let insert = beaconsTbl.insert(id <- item.id!, uuid <- item.uuid!, major <- item.major!, minor <- item.minor!)
try db.run(insert)
}
})
} catch {
print("Error creating the database")
}
fetch方法:
static func fetchBeaconsFromRestApi( completionHandler: @escaping (_ beacons: [BeaconModel]) -> ()){
Alamofire.request(Constants.Beacons.URLS.ListAllbeacons).responseArray(keyPath: "data") { (response: DataResponse<[BeaconModel]>) in
let beaconsArray = response.result.value
if let beaconsArray = beaconsArray {
completionHandler(beaconsArray)
}
}
}
它使用 Alamofire 和 AlamofireObjectMapper。你能看出我缺少了什么吗?
感谢任何帮助。