在iOS開發(fā)中,可以使用Property List(plist)文件來存儲和讀取數(shù)據(jù)。以下是創(chuàng)建和讀取plist文件的步驟:
創(chuàng)建plist文件:
寫入數(shù)據(jù)到plist文件:
獲取plist文件的路徑:
let path = Bundle.main.path(forResource: "filename", ofType: "plist")
將數(shù)據(jù)寫入plist文件:
let data = ["key": "value"]
let success = (data as NSDictionary).write(toFile: path, atomically: true)
讀取數(shù)據(jù)從plist文件:
獲取plist文件的路徑:
let path = Bundle.main.path(forResource: "filename", ofType: "plist")
讀取數(shù)據(jù)從plist文件:
if let data = NSDictionary(contentsOfFile: path) as? [String: Any] {
// 使用讀取到的數(shù)據(jù)
}
請注意,上述示例是使用Swift語言編寫的,如果使用Objective-C語言,代碼會(huì)稍有不同。