gpt4 book ai didi

swift - 无法快速增加数字

转载 作者:可可西里 更新时间:2023-10-31 23:54:53 25 4
gpt4 key购买 nike

我有一个从 keystore 填充的变量,当它递增时,会给出一个错误,内容如下:“NSNumber 不可转换为@lvalue UIint8”

if let bankbalance: AnyObject? = keystore.objectForKey("coinbalance"){
let mybalance = bankbalance as NSNumber
mybalance += 50 //this line gives the error
}

我的问题是什么可以转换为 UIint8 以便我可以添加到我的变量中?我试过 INT、Float、double。

最佳答案

你试图给 let 添加一个值,而 let 是一个常量,你不能在初始化后给 let 赋值。

苹果文档:

Constants and variables associate a name (such as maximumNumberOfLoginAttempts or welcomeMessage) with a value of a particular type (such as the number 10 or the string "Hello"). The value of a constant cannot be changed once it is set, whereas a variable can be set to a different value in the future.

var 

是你想要的

关于swift - 无法快速增加数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24833308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com