Swift 无法构造参数类型为 Int64 的字符串

Swift Cannot construct string with argument type Int64

我正在制作一款涉及 Game Center 排行榜的游戏。我想制作自定义排行榜 UI 而不是使用默认界面。

我正在尝试将游戏中心排行榜中存储的值转换为字符串,以便我可以使用 SKLabelNode 显示它们。但是,我收到一条错误消息:

Cannot invoke initializer for type 'String' with an argument list of type '(Int64?)'

我正在使用

访问 Game Center 分数
leaderboard.scores[i].value

当我使用 String(describing: ) 方法时,我的标签节点显示为 "optional(10)",括号内的分数是多少。我想知道如何将 Game Center 中的数据存储清晰地转换为字符串格式的数字。

尝试可选绑定:

if let unwrapped = leaderboard.scores[i].value {
    let string = String(unwrapped)
    print(string)
}

或者如果你想在其余范围内使用展开的值,请使用 guard 语句:

guard let unwrapped = leaderboard.scores[i].value else {
    fatalError("Couldn't unwrap the score value")
}
let string = String(unwrapped)