问题
I need to use the order
array in another class (AddOrderVievContoller.swift
class)
class OrderListViewController: UITableViewController {
var orders: [Order] = []
error message in AddOrderVievContoller.swift class: use of unresolved indentifier 'orders'
if results != nil {
orders = results as! [Order]
}
回答1:
Create a global variable:
public var orders = [String]()
place this in-between the modules your importing (import UIKit
) and the class definition:
import UIKit
public var orders = [String]()
class OrderListViewController: UITableViewController {
//viewDidLoad, etc.
}
Then you can access the orders
array in different viewControllers as you're currently trying to do.
来源:https://stackoverflow.com/questions/33900240/how-to-use-array-of-another-view-controller-class