-1

我在 iPhone 每日报价应用上做了一段时间的工作,我收到的大部分评论是使用 plist 存储报价,然后设置代码以每天随机访问报价。不过,我从来没有真正使用过 plist,并且不确定构建一个充满引号的新 plist 的最佳方法。我可以得到一些指导吗?

4

2 回答 2

1

您的 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">
<array>
    <string>A Quote</string>
    <string>A Quote</string>
    <string>A Quote</string>
</array>
</plist>

您可以像这样将 plist 打开到数组中。然后你会有一个字符串数组,你可以做任何你想做的事情。一旦你有了一个数组,我假设你知道如何从中获取一个随机对象。

[NSArray arrayWithContentsOfFile:@"myPlist.plist"];
于 2012-08-02T15:47:17.670 回答
0
<?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>files</key>
    <dict>
        <key>Resources/Info.plist</key>
        <data>
        OkWU6AfEeAr3G1LVjwgv3QVl/C4=
        </data>
    </dict>
    <key>files2</key>
    <dict>
        <key>Resources/Info.plist</key>
        <dict>
            <key>hash</key>
            <data>
            OkWU6AfEeAr3G1LVjwgv3QVl/C4=
            </data>
            <key>hash2</key>
            <data>
            bTnXxa3Ed3AQ3vCPs76DvwtUwOlgsWxMGNleo3ICfKA=
            </data>
        </dict>
    </dict>
    <key>rules</key>
    <dict>
        <key>^Resources/</key>
        <true/>
        <key>^Resources/.*\.lproj/</key>
        <dict>
            <key>optional</key>
            <true/>
            <key>weight</key>
            <real>1000</real>
        </dict>
        <key>^Resources/.*\.lproj/locversion.plist$</key>
        <dict>
            <key>omit</key>
            <true/>
            <key>weight</key>
            <real>1100</real>
        </dict>
        <key>^Resources/Base\.lproj/</key>
        <dict>
            <key>weight</key>
            <real>1010</real>
        </dict>
        <key>^version.plist$</key>
        <true/>
    </dict>
    <key>rules2</key>
    <dict>
        <key>.*\.dSYM($|/)</key>
        <dict>
            <key>weight</key>
            <real>11</real>
        </dict>
        <key>^(.*/)?\.DS_Store$</key>
        <dict>
            <key>omit</key>
            <true/>
            <key>weight</key>
            <real>2000</real>
        </dict>
        <key>^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/</key>
        <dict>
            <key>nested</key>
            <true/>
            <key>weight</key>
            <real>10</real>
        </dict>
        <key>^.*</key>
        <true/>
        <key>^Info\.plist$</key>
        <dict>
            <key>omit</key>
            <true/>
            <key>weight</key>
            <real>20</real>
        </dict>
        <key>^PkgInfo$</key>
        <dict>
            <key>omit</key>
            <true/>
            <key>weight</key>
            <real>20</real>
        </dict>
        <key>^Resources/</key>
        <dict>
            <key>weight</key>
            <real>20</real>
        </dict>
        <key>^Resources/.*\.lproj/</key>
        <dict>
            <key>optional</key>
            <true/>
            <key>weight</key>
            <real>1000</real>
        </dict>
        <key>^Resources/.*\.lproj/locversion.plist$</key>
        <dict>
            <key>omit</key>
            <true/>
            <key>weight</key>
            <real>1100</real>
        </dict>
        <key>^Resources/Base\.lproj/</key>
        <dict>
            <key>weight</key>
            <real>1010</real>
        </dict>
        <key>^[^/]+$</key>
        <dict>
            <key>nested</key>
            <true/>
            <key>weight</key>
            <real>10</real>
        </dict>
        <key>^embedded\.provisionprofile$</key>
        <dict>
            <key>weight</key>
            <real>20</real>
        </dict>
        <key>^version\.plist$</key>
        <dict>
            <key>weight</key>
            <real>20</real>
        </dict>
    </dict>
</dict>
</plist>
于 2021-11-03T01:33:42.117 回答