9
私は速くて
の新機能です。do catch
の処理を行ってもこのエラーが発生する理由を理解できません。ラインBeaconModel.fetchBeaconsFromRestApi(completionHandler: { .....
スウィフト3 - スローイング機能タイプから無効な変換
エラーとコードの一部でInvalid conversion from throwing function type '(_) throws ->(). to non-throwing function type '([BeaconModel]) ->()'
::私は同様の質問とそれらのこれまでどれを読んでいるしまし
は、このエラーを解決し
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")
}
取得方法:
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を使用します。私が逃しているものが見えますか? fetchBeaconsFromRestApi
で任意のヘルプ
ありがとうございます、この問題は解決しました。 –