我在我的代码中使用了5个SQLite.swift表。第一个表用于存储位置数据:
的DataModel:
typealias Location = (
latitude: Double,
longitude: Double,
timestamp: String,
speed: Double,
direction: Double
)
DataHelper:
class LocationDataHelper: DataHelperProtocol {
static let TABLE_NAME = "Location"
static let locations = Table(TABLE_NAME)
static let timestamp = Expression<String>("timestamp")
static let latitude = Expression<Double>("latitude")
static let longitude = Expression<Double>("longitude")
static let speed = Expression<Double>("speed")
static let direction = Expression<Double>("direction")
typealias T = Location
static func createTable() throws {
guard let DB = SQLiteDataStore.sharedInstance.TeleDB else {
throw DataAccessError.Datastore_Connection_Error
}
do {
let _ = try DB.run( locations.create(ifNotExists: true) {t in
t.column(timestamp, primaryKey: true)
t.column(latitude)
t.column(longitude)
t.column(speed)
t.column(direction)
})
} catch _ {
// Error throw if table already exists
}
}
static func insert(item: T) throws -> Int64 {
guard let DB = SQLiteDataStore.sharedInstance.TeleDB else {
throw DataAccessError.Datastore_Connection_Error
}
if (item.timestamp != "") {
let insert = locations.insert(timestamp <- item.timestamp, latitude <- item.latitude, longitude <- item.longitude, speed <- item.speed, direction <- item.direction, isDriving <- item.isDriving)
do {
let rowId = try DB.run(insert)
guard rowId > 0 else {
throw DataAccessError.Insert_Error
}
return rowId
} catch _ {
throw DataAccessError.Insert_Error
}
}
throw DataAccessError.Nil_In_Data
}
我看到这一行引发了异常:
let rowId = try DB.run(insert)
非常相似的代码在同一部手机(iPhone 6,iOS 9.2)上成功运行了我的应用中的其他4个表格。相同的代码也可以在iPhone 5s,iOS 9.2上运行而没有任何问题。
当我试图进入DB.run时,我发现故障发生在这条线的某个地方虽然我不确定它是做什么的:
dispatch_sync(self.queue, block) // FIXME: rdar://problem/21389236
接下来我应该尝试什么?如果您需要任何进一步的信息,请与我们联系。