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
import UIKit | |
class ViewController: UIViewController { | |
@IBOutlet var button:UIButton | |
@IBAction func buttonTapped(sender:AnyObject) { | |
var tappedButton:UIButton = sender as UIButton | |
tappedButton.setTitle("tapped", forState:UIControlState.Normal) | |
} |
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
// 今までの書き方 | |
#import <BlocksKit/BlocksKit.h> | |
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; | |
[button addEventHandler:^(id sender) { | |
// do something | |
} forControlEvents:UIControlEventTouchUpInside]; | |
// 2.0の書き方 |
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
// 以下は同義 | |
// __strong NSString *strongString; | |
// NSString *strongString; | |
__strong NSString *strongString = [[NSString alloc] initWithFormat:@"テスト"]; | |
__weak NSString *weakString = strongString; | |
NSLog(@"strong: %@ , weak: %@", strongString, weakString); // strong: テスト , weak: テスト | |
// 「テスト」が解放される | |
strongString = [[NSString alloc] initWithFormat:@"あいう"]; | |
NSLog(@"strong: %@ , weak: %@", strongString, weakString); // strong: あいう , weak: nil |