When I print var array = [NSManagedObject]()
I get []
in debugging window, and my tableview would not read that array.
Should I use nsfetch or what to read data from that array? I set up CoreData and it works, but when I send data to another vc with prepare for segue table view won't read var array = [NSManagedObject]()
.
Second VC aka tableview:
import UIKit
import CoreData
class TableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
var array = [NSManagedObject]()
override func viewDidLoad() {
super.viewDidLoad()
// self.array = self.bridge.item
print(array)
self.tableView.delegate = self
self.tableView.dataSource = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView:UITableView, numberOfRowsInSection section:Int) -> Int
{
return array.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
let person = array[indexPath.row]
cell.textLabel!.text = String(person)
return cell
}
}