1. 配置文件内数据
//读取
let b:String = UserDefaults.standard.string(forKey: "abc")!
print( b )
//写入
UserDefaults.standard.setValue("123", forKey: "abc")
2. 全局数据,利用AppDelegate单实例特性
//数据声明
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var strName: String = "psone"
var strPwd : String = "xbox"
....................................
}
//使用数据
let appDe = UIApplication.shared.delegate as! AppDelegate
print( appDe.strName )
本文介绍在Swift中如何通过UserDefaults进行配置文件的数据读写操作,并展示了利用AppDelegate实现全局数据存储的方法。
1062

被折叠的 条评论
为什么被折叠?



