//You can only store property list types (array, data, string, number, date, dictionary) or urls in NSUserDefaults.
如果你想保存自定义的类,那么该类必须要实现NSCoding协议,并将该类转换成NSData,才能保持到NSUserDefaults
//Attempt to insert non-property list object <NSIndexPath: 0xc000000000e00016> {length = 2, path = 0 - 7} for key selectSuCaiKey'
存
let selectSuCaiValue : NSIndexPath = indexPath
NSUserDefaults.standardUserDefaults().setValue(NSKeyedArchiver.archivedDataWithRootObject(selectSuCaiValue), forKey: "selectSuCaiKey")
NSUserDefaults.standardUserDefaults().synchronize()
取
if let data : NSData = NSUserDefaults.standardUserDefaults().valueForKey("selectSuCaiKey") as? NSData {
if let selectSuCaiValue = NSKeyedUnarchiver.unarchiveObjectWithData(data) as? NSIndexPath {
if(selectSuCaiValue.isEqual(indexPath)){
self.cardView?.backgroundColor = UIColor.redColor()
}else{}
}else{}
}else{}