Created
July 25, 2015 05:40
-
-
Save haranicle/03180f15879c3d5e69d5 to your computer and use it in GitHub Desktop.
deferについて #cswift #CodePiece
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
var handle:Handle = File.open(path) | |
// defer はスコープを抜ける直前に"必ず"実行される | |
defer { | |
print("close") | |
handle.close() | |
} | |
// 複数deferすることもできる | |
defer { | |
print("hello") | |
} | |
string.writeTo(&handle) | |
// hello, closeの順で評価される |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment