swift - 如何在 swift 中声明一个闭包的局部变量

标签 swift ios8 closures

我想声明一个闭包类型的局部变量,我该怎么做?

最佳答案

var myClosure: (myParamaterTypes) -> myReturnTypes

例如:

var myClosure: (Int, Int) -> Int  // type is (Int, Int) -> Int
myClosure = {(integer01: Int, integer02: Int) -> Int in return integer01 + integer02}

关于swift - 如何在 swift 中声明一个闭包的局部变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31657464/

相关文章:

ios - 如何在 Swift 中将 UIViewController 转换或类型转换为 AnyClass

ios - iOS 8 中的通用链接?

javascript - 这段代码片段是如何实现闭包的?

rust - 什么时候应该使用函数指针而不是闭包?

swift - 如何检查字符串是否只包含拉丁字符?

ios - 未找到“FBSDKLoginKit/FBSDKLoginKit.h”文件(适用于 iOS v4.2 和 Xcode 7 的 Facebook SDK)

ios - 根据文本标注高度

ios - 在 View Controller 中设置为背景图像的图像大小

ios - 属性类型与访问器类型不匹配

java - Java 中的闭包将如何使 API 设计取代语言设计?