Created
May 28, 2016 14:24
-
-
Save gamako/270c01681398dd4980e03f07bc67f149 to your computer and use it in GitHub Desktop.
Ruby, Underscoreライクなtapメソッドのextension実装
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 UIKit | |
protocol Tappable : class { | |
} | |
extension Tappable where Self : NSObject { | |
func tap(@noescape function: (Self) -> ()) -> Self { | |
function(self) | |
return self | |
} | |
} | |
extension NSObject : Tappable {} | |
extension UIView : Tappable {} | |
#if debug | |
func tap_example() { | |
UIView().tap { (a : UIView) in | |
print("\(a)") | |
} | |
UIStackView().tap { (a : UIStackView) in | |
print("\(a)") | |
} | |
let _ = UILabel().tap { | |
$0.text = "ほげほげ" | |
} | |
NSObject().tap { (a : NSObject) in | |
print("\(a)") | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment