gpt4 book ai didi

ios - 无法将类型 '[ViewController.Variable_Name]' 的值分配给类型 '[String]'

转载 作者:行者123 更新时间:2023-11-30 11:59:25 25 4
gpt4 key购买 nike

我试图将数组传递给另一个 UIViewController 但收到此错误:

Cannot assign value of type '[ViewController.Lugares]' to type '[String]'

对于这行代码

    if(Array[0]=="Lahua Park"){
//send me to that location
}

第一个 View Controller :

import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

...

var fetchedCountry = [Lugares]()

class Lugares{
var lugares : String

init(lugares: String){
self.lugares = lugares
}
}

...

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "segue", sender: self)
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let secondController = segue.destination as! SecondController

secondController.transferPaises = fetchedCountry (Error Ocurrs)
}

第二个 View Controller :

class SecondController: UIViewController {

var transferPaises = Array<String>()

..

override func viewDidLoad() {
super.viewDidLoad()


if (transferPaises[0]=="Mexico") {
print(transferPaises)

location.latitude = 19.432608
location.longitude = -99.133209
let region = MKCoordinateRegion(center: location, span: span)

map.setRegion(region, animated: true)

}

....

}
}

最佳答案

将其设为在 UIViewController 外部声明的公共(public)类

public class Lugares{
var lugares : String

init(lugares: String){
self.lugares = lugares
}
}

此外,更改 transferPaises 以匹配 fetchedCountry 类型

var transferPaises = [Lugares]()

关于ios - 无法将类型 '[ViewController.Variable_Name]' 的值分配给类型 '[String]',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47443838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com