Created
January 27, 2020 15:26
-
-
Save alokc83/f4656bf9a40d38e7af31a602eb4aefe0 to your computer and use it in GitHub Desktop.
Revisions
-
alokc83 created this gist
Jan 27, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ // ///////////////////////////////////////////////////////// // 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()