我正在尝试将数组传递给另一个UIViewController
但是会收到此错误:
Cannot assign value of type '[ViewController.Lugares]' to type '[String]'
这段代码
if(Array[0]=="Lahua Park"){
//send me to that location
}
First 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)
}
Second View Contoller:
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)
}
....
}
}
答案 0 :(得分:0)
transferPaises
是一个字符串数组
var transferPaises = Array<String>()
fetchedCountry
NOT 一个字符串数组:
var fetchedCountry = [Lugares]()
因此,您无法将类型Lugares
的数组分配给String
类型的数组
答案 1 :(得分:0)
将此作为在UIViewController
public class Lugares{
var lugares : String
init(lugares: String){
self.lugares = lugares
}
}
另外,将transferPaises
更改为匹配fetchedCountry
类型
var transferPaises = [Lugares]()