我想在我的应用程序上保存数据,我使用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 {}
}
Run Code Online (Sandbox Code Playgroud)