试着让它起作用,但我错了
“[string]不能转换为'string'”
var city = "Atlanta"
var issueLocation = ["Atlanta","Montreal","Toronto","XXIIVV"]
let locationRand = Int(arc4random() % 3)
var passportIdent = "Issue Location: \(issueLocation[locationRand])"
if (issueLocation == city){
}
最佳答案
var city = "Atlanta"
var issueLocation = ["Atlanta","Montreal","Toronto","XXIIVV"]
let locationRand = Int(arc4random() % 3)
var passportIdent = "Issue Location: \(issueLocation[locationRand])"
if (issueLocation == city){
}
应该是
var city = "Atlanta"
var issueLocation = ["Atlanta","Montreal","Toronto","XXIIVV"]
let locationRand = Int(arc4random() % 3)
var passportIdent = "Issue Location: \(issueLocation[locationRand])"
var randCity = issueLocation[locationRand]
if (randCity== city){
}
注意这条线
var randCity = issueLocation[locationRand]
实际获取issueLocation数组中的随机元素。然后可以使用该值与
city
变量进行比较。关于arrays - Swift [String]不能转换为'String',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27554646/