将root.plist编辑为源代码会导致plist损坏

时间:2011-10-16 21:41:13

标签: objective-c plist settings.bundle setting

我刚开始使用偏好文件,在编辑设置包中的root.plist时,我立即开始遇到问题。每次向plist添加属性时,我的XCode 4都会崩溃,同时将其编辑为属性列表。所以我想我只会编辑为源代码。这似乎要容易得多。

但是当我运行程序时,root.plist没有被读取。 (它使用来自演示程序的设置包工作正常。我正在使用InAppSettingsKit。)我查看了源代码编辑器中的root.plist,它看起来是正确的。我试着将它看作属性列表,并且我收到一条错误,指出plist已损坏。

这是我的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>PreferenceSpecifiers</key>
    <array>
<!-- Databases -->
        <dict>
            <key>Title</key>                <string>Databases</string>
            <key>Type</key>                 <string>PSGroupSpecifier</string>
        </dict>
        <dict>
            <key>Type</key>                 <string>PSToggleSwitchSpecifier</string>
            <key>Title</key>                <string>db0</string>
            <key>Key</key>                  <string>db0_preference</string>
            <key>DefaultValue</key>         <true/>
        </dict>
        <dict>
            <key>Type</key>                 <string>PSToggleSwitchSpecifier</string>
            <key>Title</key>                <string>db1</string>
            <key>Key</key>                  <string>db1_preference</string>
            <key>DefaultValue</key>         <true/>
        </dict>
<!-- Sharing Actions -->
        <dict>
            <key>Type</key>                 <string>PSGroupSpecifier</string>
            <key>Title</key>                <string>Sharing Actions</string>
        </dict>
        <dict>
            <key>Type</key>                 <string>PSToggleSwitchSpecifier</string>
            <key>Title</key>                <string>Facebook</string>
            <key>Key</key>                  <string>facebook_preference</string>
            <key>DefaultValue</key>         <true/>
        </dict>
        <dict>
            <key>Type</key>                 <string>PSToggleSwitchSpecifier</string>
            <key>Title</key>                <string>Twitter</string>
            <key>Key</key>                  <string>twitter_preference</string>
            <key>DefaultValue</key>         <true/>
        </dict>
        <dict>
            <key>Type</key>                 <string>PSToggleSwitchSpecifier</string>
            <key>Title</key>                <string>Email</string>
            <key>Key</key>                  <string>email_preference</string>
            <key>DefaultValue</key>         <true/>
        </dict>
        <dict>
            <key>Type</key>                 <string>PSToggleSwitchSpecifier</string>
            <key>Title</key>                <string>BlogSpot</string>
            <key>Key</key>                  <string>blogspot_preference</string>
            <key>DefaultValue</key>         <true/>
        </dict>
<!-- Automatic Email Enable -->
        <dict>
            <key>Type</key>                 <string>PSGroupSpecifier</string>
            <key>Title</key>                <string>Automatic Emailing</string>
        </dict>
        <dict>
            <key>Type</key>                 <string>PSToggleSwitchSpecifier</string>
            <key>Title</key>                <string>Always Send to Email</string>
            <key>Key</key>                  <string>autoblogspot_preference</string>
            <key>DefaultValue</key>         <true/>
        </dict>
<!-- Calendar -->
        <dict>
            <key>Type</key>                 <string>PSRadioGroupSpecifier</string>
            <key>Title</key>                <string>First Day of the Week</string>
            <key>Key</key>                  <string>firstDayOfTheWeek_preference</string>
            <key>Values</key>
                <array>
                    <integer>0</integer>
                    <integer>1</integer>
                    <integer>2</integer>
                    <integer>3</integer>
                    <integer>4</integer>
                    <integer>5</integer>
                    <integer>6</integer>
                </array>
            <key>Titles</key>
                <array>
                    <string>Sunday</string>
                    <string>Monday</string>
                    <string>Tuesday</string>
                    <string>Wednesday</string>
                    <string>Thursday</string>
                    <string>Friday</string>
                    <string>Saturday</string>
                </array>
        </dict>
        <dict>
            <key>
    </array>
    <key>StringsTable</key>
    <string>Root</string>
</dict>
</plist>

1 个答案:

答案 0 :(得分:2)

在plist的最后,你有一个悬空键和dict标签。

第90行和第91行。

        </dict>
        <dict>
            <key>
    </array>
    <key>StringsTable</key>
    <string>Root</string>
</dict>
</plist>

应该是这样的:

        </dict>
        <dict />
    </array>
    <key>StringsTable</key>
    <string>Root</string>
</dict>
</plist>

        </dict>
        <dict>
            <key>key</key><string>string</string>
        </dict>
    </array>
    <key>StringsTable</key>
    <string>Root</string>
</dict>
</plist>

我使用TextMate发现了这一点。捆绑 - &gt;物业清单 - &gt;验证语法。不会告诉你确切的问题,但会带你到该地区。

您还可以尝试在属性列表编辑器应用程序中打开plist来查看行#(/ Developer / Applications / Utilities / Property List Editor.app)

Plists是XML,因此任何XML验证器都会在语法中发现主要问题。但经验法则是,每个标签都需要一个贴标签。对于每个键,您需要一个值。 空标记应为<tag />而不是<tag></tag>