** readData.plist为:**
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>currentChapter</key>
<string>2</string>
<key>currentLine</key>
<string>2</string>
<key>bookname</key>
<string>ExcelBible</string>
</dict>
</plist>
**以下是代码:**
let Chapter = currentChapter
let Line = currentLine
let name = bookname
let dict:NSMutableDictionary = NSMutableDictionary()
dict.setObject("1", forKey: "currentChapter" as NSCopying)
dict.setObject("1", forKey: "currentLine" as NSCopying)
dict.setObject("WordBible", forKey: "bookname" as NSCopying)
//I also use dict[0] = "1", and setValue() method both of them are not work
let plistPath = Bundle.main.path(forResource: "readData", ofType: "plist")
dict.write(toFile: plistPath!, atomically: true)
Blockquote我也在这里使用FileManager和几个示例来保存数据,其中一些显示为“ Successfully write”,但文件没有更改。
Blockquote
[我是2020年2月12日,我是iOS开发人员
我认为该文件不在可写位置,因此应在documents目录中创建它。然后,必须从文档目录中读取它。