Eric Yu Eric Yu -5 years ago 143
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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download