// ///////////////////////////////////////////////////////// // For Loops 2 // ///////////////////////////////////////////////////////// import Foundation /// Use of .some in For loop with `for case let` func usingForCaseLet() { print("\n-----------Result for function \(#function) -----------") // .some let data: [Any?] = ["IronMan", nil, 1989, "SpiderMan#1"] for case let .some(element) in data { print(element) } // .optional for case let element? in data { print("With ? \(element)") } } usingForCaseLet() /// Using `case let` to filter the array func usingForCaseLetForFiltering() { print("\n-----------Result for function \(#function) -----------") enum CarState { case running(speed: Int) case stopped case idling } let runningSpeeds: [CarState] = [ .running(speed: 40), .stopped, .idling, .running(speed: 90), .idling, .running(speed: 10) ] for case let .running(speed) in runningSpeeds { print("speed is \(speed)") } } usingForCaseLetForFiltering()