xcode - 找不到类型为 'String' 的初始值设定项,它接受类型为“(格式 : String, 参数:UInt32

标签 xcode swift syntax-error

我在 Xcode 6.3 (6D570) 中创建了一个 Playground 并输入以下代码:

import UIKit
var randum_num = arc4random_uniform(13) + 1
String(format: "card%i", arguments: randum_num)

我得到了这个错误:

cannot find an initializer for type 'String' that accepts an argument list of type '(format: String, argument: UInt32

抱歉,我是 Swift 的新手,感谢您的任何建议!

附言我正在学习本教程:link

最佳答案

你只需要省略“arguments:”。像这样尝试:

let randum_num = arc4random_uniform(13) + 1
String(format: "card%i",  randum_num)

或者只是

String(format: "card%i",  arc4random_uniform(13) + 1)

关于xcode - 找不到类型为 'String' 的初始值设定项,它接受类型为“(格式 : String, 参数:UInt32,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29724932/

相关文章:

swift - Xcode Swift Language Version,未指定和版本之间有什么不同?

ios - 无法在 Swift 项目中构建 facebook ios SDK

ios - 允许用户使用来自不同 View Controller 中标签的文本创建新的 tableViewCells?

ios - 从 UITabBarController 呈现 ViewController 标签

javascript - 为什么{a :1} evaluate to 1 in the console

reactjs - 未封闭的正则表达式ReactJS错误

ios - xcode出现错误时显示自定义框架的实现

xcode - 如何安装 OSX 10.4u SDK 以支持向后兼容的 OSX 版本?

ios - UIViewController 内容未显示在 Storyboard上

java - 为什么 Java 在 While 循环中跳过我的 If 语句?