LoginSignup
9
8

More than 5 years have passed since last update.

swiftでblocksのproperty宣言

Posted at

Objective-C

@interface Hoge

@property (nonatomic, copy) void(^onClick)(NSString *);

@end 
Hoge *hoge = [[Hoge alloc] init];
hoge.onClick = ^(NSString *text) {
    NSLogt(@"%@", text);
};

Swift

class Hoge {
    var onClick: ((String) -> Void)?
}

func f(text: String) {
    println(text)
}

var hoge = Hoge()
hoge.onClick = f
9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8