swift - 初始化前使用的常量

标签 swift

<分区>

let errorCodestring : String?

if let theError = errorCodestring {
    print(theError)
}

在上面的代码中,Xcode 抛出了错误:

constant 'errorCodestring'being used before being initialized

代码有什么问题,如何清除错误?

最佳答案

您必须在使用常量之前对其进行初始化。

let errorCodestring : String? = nil

关于swift - 初始化前使用的常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53230836/

相关文章:

ios - 为什么图像没有被添加到数组中?

objective-c - 将 NSArray 转换为 NSMutableArray Swift

swift - 如何在swift中通过web api将图像保存到数据库表

swift - 如何在设备(或常量)地址空间中创建缓冲区?

ios - 动画 NSLayoutConstraint 乘数和/或处于事件状态

Swift 游戏错误信息

swift - 无法在泛型函数中返回 nil

ios - 如果缺少字段,则解析注册到下一个 View Controller

ios - Firebase 和 iOS : FIRAuthInternalErrorDomain "MISSING_IDENTIFIER" when trying to login with custom token

arrays - 在 [SomeProtocol] 类型的数组中查找对象的索引