找不到类型' String'的初始值设定项。接受类型'的参数列表(格式:字符串,参数:UInt32

时间:2015-04-19 01:53:15

标签: xcode swift syntax-error

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

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中完成了新功能,感谢您的任何建议!

P.S。我遵循本教程:link

1 个答案:

答案 0 :(得分:13)

你只需要省略"参数:"。试试这样:

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

或只是

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