gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 05:50:00 25 4
gpt4 key购买 nike

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

}

最佳答案

试试 SwiftKeyChainWrapper - Link

这是一个有用的库,用于在设备上保存敏感数据。

用法

将字符串值添加到钥匙串(keychain):

let saveSuccessful: Bool = KeychainWrapper.standard.set("Some String", forKey: "myKey")

从钥匙串(keychain)中检索字符串值:

let retrievedString: String? = KeychainWrapper.standard.string(forKey: "myKey")

从钥匙串(keychain)中删除一个字符串值:

let removeSuccessful: Bool = KeychainWrapper.standard.removeObject(forKey: "myKey")

关于ios - 有什么方法可以在 iOS 中使用 swift 将用户名和密码保存在设备中,这与 Android 中的偏好相同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33590842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com