Accessing element of an array with iterator instead of position in Swift -
I would like to know that Swift has an iterator for the switcher, such as in CPP, which is the position Use Actually, I use position + 1 in my array to access my next element: zero) {var Str = string () var myFunc: (int -> zero)! MyFunc = {If $ 0 & lt; Array.count {str + = array [$ 0] myFunc ($ 0 + 1)} and {success (str)} myFunc (0)} arrayToString ({println ($ 0)}) I find a useful solution like this: Any suggestions? What do you want to use the generator: sir array = ["a" , "B", "c", "d"] var g = array.generate () var str = for string () next (); i! = Nil; i = g.next () ) {Str + = i! } This is very easy when you want to parse the command line argument: In Swift 3, it is now:
var array = ["a", "b", "c", "d"] func arrayToString (success: string -> Zero) {var str = string () var myFunc: (Iterator -> Zero)! MyFunc = {if $ 0! {{Println ($ 0)}) = {{str + = array [$ 0] myFunc ($ 0.next)} other {success (str)} myFunc (array.first)} arrayToString (
var args = Process.arguments.generate () while arg = Args .next () {if (arg == "--output") {output = args.next ()! ...}}
var args = Process.arguments.makeIterator () while Arg = Args Give next () {if (arg == "--output") {output = args.next ()! ...}}
Comments
Post a Comment