【发布时间】:2017-09-15 23:26:59
【问题描述】:
我想测试一个数组的计数是否大于0,否则关闭当前视图。
现在我正在这样做:
do {
let pets = try self.managedObjectContext.fetch(request)
guard pets.count > 0 else {
self.dismiss(animated: true, completion: nil)
}
dateCreated = Date(timeIntervalSince1970: Double(pets[0].dateCreated))
} catch {
self.dismiss(animated: true, completion: nil)
}
我想知道如果计数不大于0,我是否可以手动将do..catch 发送到catch,这样我就不必写两次self.dismiss(animated: true, completion: nil)。有人知道这是否可能吗?
【问题讨论】: