【发布时间】:2016-07-12 19:37:56
【问题描述】:
我正在尝试从我的 Firebase 数据库中提取信息并使用它来创建 Order 类型的对象。我在 catch 语句中打印的错误如下。
错误域=myProjectName.OrderError Code=0 "(null)"
我不确定这究竟意味着什么,或者如何解决它。 我在我的 Order 类中定义了一个自定义错误类型,如下所示。
enum OrderError: ErrorType
{
case IllegalOrderNumber
case InvalidEntry
}
错误是由以下代码sn-p产生的。
self.ref.child("orders").observeEventType(.ChildAdded, withBlock: { (snapshot) in
let pickupLoc = snapshot.value!["pickupLocation"] as? String
let dropoffLoc = snapshot.value!["dropoffLocation"] as? String
let orderNumInt = snapshot.value!["orderNum"] as? Int
//since the database will return nil if you try and cast a string to an int
//we get it as an int then cast to string
let orderNum = String(orderNumInt)
do
{
let myOrder = try Order(PickUpLoc: pickupLoc, DropOffLoc: dropoffLoc, OrderNum: orderNum)!
self.orders.append(myOrder)
}
catch let error as NSError
{
//should never get here
print(error)
}
})
当用户将值输入数据库时,我会进行所有错误检查,因此应该没有理由产生错误。
【问题讨论】:
-
设置断点并打印
error.description,它会打印什么? -
如我上面所说的那样打印
Error Domain=myProjectName.OrderError Code=0 "(null)"
标签: ios swift firebase firebase-realtime-database