Skip to content

Swift samples - #1

Open
askrav wants to merge 3 commits into
HowProgrammingWorks:masterfrom
askrav:master
Open

Swift samples #1
askrav wants to merge 3 commits into
HowProgrammingWorks:masterfrom
askrav:master

Conversation

@askrav

@askrav askrav commented May 25, 2017

Copy link
Copy Markdown

No description provided.

@tshemsedinov
tshemsedinov requested review from GYFK and Gagnant May 25, 2017 19:37
@GYFK
GYFK requested a review from GreatAndPowerfulKing June 6, 2017 21:48

@GYFK GYFK left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

@GreatAndPowerfulKing GreatAndPowerfulKing left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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 }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I supposed that space before (x) is excessive.

print($0)
}

[7,10,1,5].forEach {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would advise to add spaces between elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants