Swift samples - #1
Conversation
GYFK
left a comment
There was a problem hiding this comment.
@Inquisitor0 generally is ok. However you should also provide an example of iteration not only over the Array.
And it would be nice to add break via label in the break example. The syntax may be rather exotic but it is worth mentioning.
There was a problem hiding this comment.
@Inquisitor0 Good job!
But I'll ask you to add some examples: iterating over Dictionary and flatMap usage (+ demonstration of difference between map and flatMap).
|
|
||
| while (true) { | ||
| print("Hello") | ||
| if flag { break } |
There was a problem hiding this comment.
Styling mark: I don't like single line control flow statements, but it's up to you.
| @@ -0,0 +1,8 @@ | |||
| //: stride(from:to:by:) iterating over collection. C-style loop has been removed | |||
| for i in stride(from: 0, to: 10, by: 1) { | |||
There was a problem hiding this comment.
I suppose it would be better to show how to use decimal loop bounds and increment. E. g. for i in stride(from: 1.3, to: 8.5, by: 1.7) { … }. Because current example may be easily replaced with its preferred variant: for i in 0..<10 { … }.
| let a = [7, 10, 1, 5, 2] | ||
|
|
||
| a.forEach { x in | ||
| print (x) |
There was a problem hiding this comment.
I supposed that space before (x) is excessive.
| print($0) | ||
| } | ||
|
|
||
| [7,10,1,5].forEach { |
There was a problem hiding this comment.
I would advise to add spaces between elements.
No description provided.