I'm having a news ViewController
and a TeamViewController
. The TeamViewController
contain a tableView of teamObjects which when selected is added into array. I want to add this array into NSUserDefaults
so i can access them from the NewsController
which contain a url request where the teamObjects is needed. However i keep getting:
'Attempt to insert non-property list object ( "" ) for key teams'
I'm open for other suggestions if there is better ways than storing it in NSUserDefaults
didSelectRowAtIndexPath
method
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
let team = self.teamArray[indexPath.row] as Team
var removed = false
for (index, value) in enumerate(self.teamSelected) {
if (value == team) {
self.teamSelected.removeAtIndex(index)
removed = true
}
}
if (!removed) {
self.teamSelected.append(team)
}
var userDefaults = NSUserDefaults.standardUserDefaults()
userDefaults.setValue(self.teamSelected, forKey: "teams")
userDefaults.synchronize()
tableView.reloadData()
}
My object
class Team: NSObject{
var id: Int!
var name: NSString!
var shortname: NSString!
init(id: Int, name:NSString, shortname: NSString) {
self.id = id
self.name = name
self.shortname = shortname
}
}