小编Anh*_*inh的帖子

有没有什么方法可以在iOS中使用swift来保存用户名和密码,这与Android中的偏好相同?

我想在我的应用程序上保存数据,我使用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)

cookies ios swift

9
推荐指数
3
解决办法
7206
查看次数

标签 统计

cookies ×1

ios ×1

swift ×1