我更新到新的 Swift 1.1。我有一个可选变量:
let bookingButton: GreenButton?
当我尝试将此 UIView 子类添加为 subview (self 是 UIView)时,出现以下错误:
Immutable value '' may not be passed inout
有什么想法吗?
最佳答案
inout 指定一个可以被函数改变的参数。这里你传递了一个let
(一个不可变的参数)所以这是不兼容的。您可以将 lookingButton
从 let
更改为 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/