ios - Swift infinite loop while iterating array -


i have protocol defined as...

@objc protocol mydatasource : class {      var currentreportlistobjects:[reportlistobject] { }; } 

and code iterate returned array (as nsarray objc) in swift as...

            if let reportlistobjects = datasource?.currentreportlistobjects {                  reportlistobject:reportlistobject? in reportlistobjects {                      if let report = reportlistobject                     {                         // useful 'report'                     }                 }             } 

if reportlistobjects array nil, stuck in infinite loop @ for-loop. equally, if there data in array, iterated , 'something useful' done until end of array reached loop not broken , continues infinitely.

what doing wrong? or there blindingly obvious i'm missing here?

you've added lot of optionals here confusing things. here's mean:

for report in datasource?.currentreportlistobjects ?? [] {    // useful 'report' } 

if datasource has value, iterate on currentreportlistobjects. otherwise iterate on empty list.

if did want break out, rather using ??, mean this:

if let reportlistobjects = datasource?.currentreportlistobjects {     report in reportlistobjects {         println(report)     } } 

there's no need intermediate reportlistobject:reportlistobject? (and that's source of problem, since accepts nil, usual termination of generator).


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -