how to loop through array(s) of optionals

This comes up a lot (for years) and has me buggered. 


  1. class Act: Codable {
  2.    var a:  Uint32
  3.    var b: [UInt32]?
  4. .
  5. .
  6. .
  7.    var z: [UInt32]?
  8.    init( …vars…)
  9. }


I want to do a simple sum on .nonzerobitCount for every var a through z.


I can write code to check,e.g.,


10. if Act.b != nil {for index in 0..


but even with copy and paste this is exhausting and cludgy.

Powered by WPeMatico

You may also like...

Comments are closed.