-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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] |
There was a problem hiding this comment.
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] { |
There was a problem hiding this comment.
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) = { |
There was a problem hiding this comment.
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: () -> ()) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
.
No description provided.