Eric Yu Eric Yu - 4 months ago 5
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() {

... 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


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