Eric Yu Eric Yu - 5 months ago 15
Swift Question

pass array to singleton (swift)

class MySingleton{
static let shareInstance = MySingleton()
private init() {}

var myDetail = [Detail]()
}

class DetailTableViewController {

var expense = [Detail]()

override func viewDidLoad() {
super.viewDidLoad()

... put stuff in expense array ....


MySingleton.shareInstance.myDetail = expense //<--- doesn't work
// error is "cannot assign value of type '[Detail]' to type [MySingleton.Detail]"
}
}


How do I copy an array to my MySingleton?
right now i just pass my array around my classes using segue

Answer

From your error, it is likely you are defining Detail twice, once locally to the singleton, once globally for the viewController.

Comments