I have a protocol defined as...
@objc protocol MyDatasource : class {
var currentReportListObjects:[ReportListObject] { get };
}
and some code to iterate the returned array (as an NSArray from ObjC) in Swift as...
if let reportListObjects = datasource?.currentReportListObjects {
for reportListObject:ReportListObject? in reportListObjects {
if let report = reportListObject {
// Do something useful with 'report'
}
}
}
If my reportListObjects array is nil, I get stuck in an infinite loop at the for-loop. Equally, if there is data in the array, it is iterated and 'something useful' is done until the end of my array is reached but the loop is not broken and continues infinitely.
What am I doing wrong? Or is there something blindingly obvious I'm missing here?
ReportListObject(non-optional), but you'refor-insaysReportListObject?... andNSArrayis probablynil-terminated... change the type in thefor-into be non-optional (or just let it implicitly infer the type)?