Cannot subscript a value of type [String] with an index of type “UInt32”

前端 未结 2 498
自闭症患者
自闭症患者 2020-12-11 22:16

i\'ve been trying to create a code to generate random names. Here it is

import UIKit

 let arrayOfNames: [String] = [\"Giovanni\", \"Simone\", \"Francesco\",         


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-11 22:51

    You should use an Int to access an array by index

    Replace this

    var casual1 = arc4random_uniform(7)
    var casual2 = arc4random_uniform(7)
    

    with this

    var casual1 = Int(arc4random_uniform(7))
    var casual2 = Int(arc4random_uniform(7))
    

提交回复
热议问题