Skip to content

Swift3 samples #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Swift3 samples #1

wants to merge 4 commits into from

Conversation

askrav
Copy link

@askrav askrav commented May 26, 2017

No description provided.

@tshemsedinov tshemsedinov requested review from Gagnant and GYFK May 26, 2017 13:42
@GYFK GYFK requested a review from GreatAndPowerfulKing June 6, 2017 21:57
Copy link

@GreatAndPowerfulKing GreatAndPowerfulKing left a comment

Choose a reason for hiding this comment

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

@Inquisitor0 I’ll ask you to add an example of a strong reference cycle avoidance while using closures.

Also, I suppose you should provide more meaningful examples. E. g. in your example of autoclosures you show how to use them but it’s not clear why it’s useful in a particular case. You may check examples provided by Apple in "The Swift Programming Language" book to follow their style.

return x * x
}

let myArray = [0,1,2,3,4]

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 names like myArray and I'll advice to add spaces between array's items (like [0, 1, 2...])

}

let myArray = [0,1,2,3,4]
func through(array arr: [Int], f: (Int) -> (Int)) -> [Int] {

Choose a reason for hiding this comment

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

f – bad external parameter name.

/*: ###
Without explicitly declaring "x", you can use $0 as parameter:
*/
var squareAgain: (Int) -> (Int) = {

Choose a reason for hiding this comment

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

@Inquisitor0 More imagination please. E. g. you may replace squareAgain with multiply.

@@ -0,0 +1,35 @@
//: [Simple closure](@previous)

func repeatFunc(num: Int, f: () -> ()) {

Choose a reason for hiding this comment

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

It would be much better to provide more meaningful external names and perhaps swap parameters. E. g. func repeatFunc(_ function: () -> (), times: Int). Maybe provide different external and internal names, It's up to you.

Swapping isn't required, 'cause it will make impossible to use this function with a trailing closure. But you should update function's signature to make it more meaningful.

@@ -0,0 +1,16 @@
//: [Escaping closure](@previous)

struct Test {

Choose a reason for hiding this comment

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

Test – bad name.

}
}

func testFunc(isEnabled: Bool, closure: @autoclosure () -> Test) {

Choose a reason for hiding this comment

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

testFunc – bad name.


private(set) var funcList: [ClosureType] = []

mutating func append(aFunction: @escaping ClosureType) {
Copy link

@GreatAndPowerfulKing GreatAndPowerfulKing Jun 7, 2017

Choose a reason for hiding this comment

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

As for me, I'd replace aFunction with function.

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.

2 participants