我收到了这个错误......
[2017-02-27 15:11:23] NONE us us_crdrscrdrsge NONE
[2017-02-27 15:11:23] brea crdrs crdrs_ar united states
[2017-02-27 15:11:23] brea crdrs crdrs_daz1 united states
[2017-02-27 15:11:23] brea crdrs crdrs_dev united states
[2017-02-27 15:11:23] brea crdrs crdrs_devgen united states
[2017-02-27 15:11:24] NONE us us_ctabscaninv NONE
[2017-02-27 15:11:24] NONE us us_ctabscanstmt NONE
fatal error: unexpectedly found nil while unwrapping an Optional value
2017-02-27 15:11:24.111276 Mobile[647:47234] fatal error:
unexpectedly found nil while unwrapping an Optional value
如何防止此for循环中的nil值:
```
let apResults = realm.objects(DestinationNoEnum.self).
filter("destinationRegionCode = 'ap'")
for aps in apResults {
autoreleasepool {
print("\(aps.destinationCity) \(aps.destinationCode)
\(aps.destinationName) \(aps.destinationCountry)")
}}
apResults数组是通过领域查询创建的。数据库中有1000个条目。
答案 0 :(得分:2)
试试这个:
for aps in apResults where aps != nil {
// do your things
}