我想在我的应用程序中保存数据,我使用DataCore进行保存,但它会将数据保存在一个实体中,并且该实体的一个属性可以保存许多不同的值。我需要将数据保存为Android偏好设置中每个属性仅保存一个值。我该怎么做?请帮帮我。谢谢。
这是我的代码:@IBAction func SaveAll(sender: AnyObject) {
let username:String = user_name.text!
let password:String = pass_word.text!
let appDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let context:NSManagedObjectContext = appDel.managedObjectContext
let newStu = NSEntityDescription.insertNewObjectForEntityForName("Student", inManagedObjectContext: context) as NSManagedObject
newStu.setValue(username, forKey: "userName")
newStu.setValue(password, forKey: "passWord")
do {
try context.save()
} catch {}
}