前提:我是 Swift 的新手。
我试图将名为 fields.plist 的 plist 文件的内容加载到数组(称为“RootArray”)中。
这是 fields.plist 文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "..." "...">
<plist version="1.0">
<array>
<array>
<string>Question number one</string>
<dict>
<key>783612</key>
<string>Option number one 1</string>
<key>234739</key>
<string>Option number two 1</string>
<key>346837</key>
<string>Option number three 1</string>
</dict>
</array>
<array>
<string>Question number two</string>
<dict>
<key>928732</key>
<string>Option number one 2</string>
<key>263127</key>
<string>Option number two 2</string>
<key>332877</key>
<string>Option number three 2</string>
</dict>
</array>
</array>
</plist>
如何从中获取数组?谢谢!
最佳答案
Checking about "what's a way to store data locally in a command-line swift program". Found this comment: "Command line tools do use the Bundle structure: in other words, Bundle.main returns a valid bundle for the directory containing the command line executable. Bundle.main.resourceURL returns the url for the parent directory. Bundle.main.pathForResource("file", ofType:"xyz") would return a valid path provided file.xyz is copied into the same directory as the command line tool"
关于arrays - 在 Swift 中读取 plist 文件的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48010979/