OMG, for the life of me I can't get this to work.
typdef
in objective-c that looks like this:typedef void (^StringBlock)(NSString * string);
StringBlock
type. That property is declared in objective-c like this:@property (nonatomic, copy) StringBlock onTextSubmitBlock;
input.onTextSubmitBlock = ^(NSString * text) {
};
input!.onTextSubmitBlock = {(StringBlock) in
}
That compiles, but I have no access to the argument I need ((NSString * text)
in objective-c...)
I'm sure that once I get used to Swift this will be obvious, but what am I missing?
You are pretty close. You should be able to use it like this:
input!.onTextSubmitBlock = { text in
println(text)
}
Swift will infer that text
is an NSString
from the declaration. Thera are a couple alternative ways you could declare this as well. Like this:
input!.onTextSubmitBlock = {
println($0) // $0 is text
}
And this:
input!.onTextSubmitBlock = { (text: NSString) -> () in
println(text)
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments