[英]How to write this objective-c block in swift syntax?
I recently switched from working with Objective-C to Swift and now I am facing the following objective-c block. 我最近从使用Objective-C切换到Swift,现在我面对以下的Objective-C模块。 I cannot figure out how to write it in Swift (1.2) syntax .
我不知道如何用Swift(1.2)语法编写它。 This is how the block is defined in objective-c:
这是在objective-c中定义块的方式:
formatter = ^(CGFloat value){
// do something with value
return "stringrepresentation";
};
Could someone be kind and show me the correct syntax? 有人能和kind并告诉我正确的语法吗?
ADDITIONAL Info: the "formatter" value needs to be of type ValueFormatter
其他信息: “格式器”值必须为
ValueFormatter
类型
How to achieve this? 如何实现呢?
That would look like this: 看起来像这样:
let formatter = { (value: CGFloat) -> String in
// do something with value
return "the formatted thing"
}
The type of formatter
will be (CGFloat) -> String
. formatter
的类型为(CGFloat) -> String
。
SWIFT 2 SWIFT 2
Block Declarations 块声明
var myCallBack:((Bool)->Void)? = nil
Block sending back 阻止发回
self.myCallBack!(true)
Block Receiving back 阻止收货
myCallBack = { (isSuccess: Bool)-> () in
//perform action you want to
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.