我一直在尝试创建代码以生成随机名称。这里是
import UIKit let arrayOfNames: [String] = ["Giovanni", "Simone", "Francesco", "Ahmet", "Valerio", "Federico"] let arrayOfsNames: [String] = [" İl Genio", " Lo scemo", " Verga", " Fermi", " Medici", " L'assasino"] var casual1 = arc4random_uniform(7) var casual2 = arc4random_uniform(7) let name = "\(arrayOfNames[casual1]) + \(arrayOfsNames[casual2])" name
但是在“ let name”行上,这给了我标题上的错误。有谁知道为什么以及如何解决它?
您应该使用Int来按索引访问数组
Int
取代这个
var casual1 = arc4random_uniform(7) var casual2 = arc4random_uniform(7)
有了这个
var casual1 = Int(arc4random_uniform(7)) var casual2 = Int(arc4random_uniform(7))