Last active
August 31, 2016 00:52
-
-
Save fromkk/6f58e87180c7cd5d6951f0b6f23c4385 to your computer and use it in GitHub Desktop.
.@codelynx1 さんの発表を参考にif文とwhile文を日本語で作ってみた。これは闇が深そうだ。。 #iOSDCRC #CodePiece
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
import Foundation | |
//Swift 2.2 | |
public func もし(val: Bool, @noescape _ closure: () -> Void) -> Void { | |
if val { | |
closure() | |
} | |
} | |
public func 間(@autoclosure check: (Void) -> Bool, @noescape _ closure: () -> Void) -> Void { | |
while (check()) { | |
closure() | |
} | |
} | |
もし(true) { | |
print("OK") | |
} | |
var loop = 0 | |
間 (loop < 10) { | |
loop += 1 | |
print (loop) | |
} | |
//Swift 3 | |
public func もし(_ val: Bool, _ closure: @noescape () -> Void) -> Void { | |
if val { | |
closure() | |
} | |
} | |
public func 間( _ check: @autoclosure (Void) -> Bool, _ closure: @noescape () -> Void) -> Void { | |
while (check()) { | |
closure() | |
} | |
} | |
もし(true) { | |
print("OK") | |
} | |
var loop = 0 | |
間 (loop < 10) { | |
loop += 1 | |
print (loop) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment