找不到类型“字符串"的初始值设定项,它接受类型为“(格式:字符串,参数:UInt32)的参数列表 [英] cannot find an initializer for type 'String' that accepts an argument list of type '(format: String, argument: UInt32

查看:30
本文介绍了找不到类型“字符串"的初始值设定项,它接受类型为“(格式:字符串,参数:UInt32)的参数列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I created a playground in Xcode 6.3 (6D570) and input these following code:

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 的新手,感谢您的建议!

Sorry I'm complete new in Swift, thanks for any advices!

附言我正在关注本教程:link

P.S. I'm following this tutorial: link

推荐答案

您只需省略参数:".试试这个:

You just have to omit "arguments:". Try like this:

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

或者干脆

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

这篇关于找不到类型“字符串"的初始值设定项,它接受类型为“(格式:字符串,参数:UInt32)的参数列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆