What is the shortest way to run same code n times in Swift? -
i have code need run n
times in swift. shortest possible syntax that?
i using for
loop lot of typing.
for in 0..<n { /* */ }
is there shorter/nicer way running same code n
times in swift?
sticking for
loop - extend int
conform sequencetype
able write:
for in 5 { /* repeated 5 times */ }
to make int
conform sequencetype
you'll following:
extension int : sequencetype { public func generate() -> rangegenerator<int> { return (0..<self).generate() } }
Comments
Post a Comment