ios - Swift 错误 - 不可变值 '' 可能无法传入

标签 ios xcode swift ios7 ios8

我更新到新的 Swift 1.1。我有一个可选变量:

let bookingButton: GreenButton?

当我尝试将此 UIView 子类添加为 subview (self 是 UIView)时,出现以下错误:

Immutable value '' may not be passed inout

enter image description here

有什么想法吗?

最佳答案

inout 指定一个可以被函数改变的参数。这里你传递了一个let(一个不可变的参数)所以这是不兼容的。您可以将 lookingButtonlet 更改为 var 以解决此问题。

如 Apple 文档中所述:

You can only pass a variable as the argument for an in-out parameter. You cannot pass a constant or a literal value as the argument, because constants and literals cannot be modified. You place an ampersand (&) directly before a variable’s name when you pass it as an argument to an inout parameter, to indicate that it can be modified by the function.

关于ios - Swift 错误 - 不可变值 '' 可能无法传入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28429446/

相关文章:

ios - UITableView 在 TabBar 下

ios - 我想将占位符日期显示为当前日期

使用 alamofire 在 Swift 中解析 Json

cocoa - Xcode 3.2 在选定文本中查找和替换

xcode - 如何初始化相互依赖的属性

ios - 使用矢量图像集时如何避免自定义 UIButton 中的图像扭曲和拉伸(stretch)?

ios - Xcode 7 swift, '' 没有用 objective-c 选择器(函数)声明的方法”警告

ios - 即使应用程序处于后台模式或终止模式,如何检查是否有人进入/离开特定边界区域?

ios - swift 继承协议(protocol)方法重写

c# - 单触摸应用程序中的内存问题