Created
June 8, 2014 11:53
-
-
Save ryugoo/00ec5ac8be648f020103 to your computer and use it in GitHub Desktop.
Swift closure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass { | |
// Instance variables | |
var myStr: String | |
// Constructor | |
init() { | |
myStr = "Hello " | |
} | |
// Method | |
func myFunc(value:String) -> String { | |
var myClosure: (String) -> (String) = { | |
[unowned self] (value: String) -> (String) in | |
let retStr = self.myStr + value | |
return retStr | |
} | |
return myClosure(value) | |
} | |
func myMethod(value:String) -> String { | |
let retStr = self.myStr + value | |
return retStr | |
} | |
} | |
let myInstance = MyClass() | |
myInstance.myFunc("World") | |
myInstance.myMethod("World") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment