Created
July 7, 2015 02:03
-
-
Save Nadohs/ea7ea393ba4fb8b35fa2 to your computer and use it in GitHub Desktop.
defer syntax in Swift 1.2
This file contains 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 defering{ | |
// func g <T>(T? -> T?){ | |
// | |
// } | |
var defers:[(Void -> Void)] = [] | |
func fer( df:Void -> Void){ | |
defers.append((df)); | |
} | |
deinit{ | |
for f in defers{ | |
f(); | |
} | |
} | |
} | |
func testingDef(){ | |
let de = defering() | |
let a = 1; | |
print("test1\n") | |
let b = 2; | |
de.fer{ | |
print("test2 a\(a)\n") | |
} | |
var test:Void -> Void = { | |
print("tested!\n\n\n") | |
} | |
test() | |
let c = 3; | |
de.fer{ | |
print("test3 b\(b) c\(c)\n") | |
} | |
let d = 1; | |
// return; | |
print("test4\n") | |
} | |
testingDef() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment