How to use array of another view controller class?

主宰稳场 提交于 2020-01-17 13:51:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!