arrays - 在 Swift 中读取 plist 文件的内容

标签 arrays swift xcode macos command-line

前提:我是 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/

相关文章:

c - 如何通过 C 中的函数操作字符串数组?

c - 使用 sscanf 解析不会保留数组以供后续使用

ios - 动画不执行

Swift - 在不同的类中重复相同的代码并更改一个项目

swift - 排序结构 -> 二元运算符 '<' 不能应用于两个 'String?' 操作数

java - 如何从 Arraylist 中删除偶数索引直到列表变空?

php - 使用 PHP 在 for 循环中使用 mysql 查询的困难

Xcode:我应该在复制期间去除调试符号吗?

iphone - 在 Objective-C 中使用 WebSocket

ios - 为什么观点没有改变? Xcode/swift 2