CoreData 未将类型设置为 XML

发布于 2025-01-08 09:46:50 字数 677 浏览 0 评论 0原文

我很难调试我的数据(CoreData、NSPersistentDocument)的问题。

我有一个 NSPersistentDocument 的子类。我正在使用 NSManagedObject 子类/标准核心数据模型。我没有在 NSPersistentDocument 或 NSManagedObject 类中做任何特殊的事情。我只是创建一个对象(在 NSPersistentDocument 的子类中):

[NSEntityDescription insertNewObjectForEntityForName:@"ModelName" 
    inManagedObjectContext:[self managedObjectContext]];

当我尝试将文档保存在我的应用程序中时,有一个文件格式的下拉菜单。它包括 Binary(默认)、SQLite 和 XML。我将文件另存为 XML。当我尝试查看它(使用 less,甚至在 Finder 中打开)时,我发现该文件存储为二进制文件。

我需要做一些特殊的事情来将其强制转换为 XML 吗?

根据 Apple 的文档,我的理解是,在使用 NSPersistentDocument 子类时,我不需要进行设置 NSPersistentStore 或 NSPercientStoreCoordinator 的工作。我的理解是这一切都是免费的。据我所知,XML 是默认的。

I'm having a hard time debugging a problem with my data (CoreData, NSPersistentDocument).

I have a subclass of NSPersistentDocument. I am using NSManagedObject subclasses / standard Core Data models. I'm not doing anything special in NSPersistentDocument or with the NSManagedObject classes. I am merely creating an object (in NSPersistentDocument's subclass):

[NSEntityDescription insertNewObjectForEntityForName:@"ModelName" 
    inManagedObjectContext:[self managedObjectContext]];

When I attempt to save the document in my app, there is a drop-down for file formats. It includes Binary (default), SQLite, and XML. I save the file as XML. When I try to view it (using less, or even opening in Finder), I find that the file is stored as binary.

Is there something special I need to go to force it to XML?

My understanding based on the documentation from Apple is that in using an NSPersistentDocument subclass, I don't need to do the work of setting up the NSPersistentStore or NSPersistentStoreCoordinator. My understanding is all of this comes for free. Also from what I've read, XML is the default.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寻找一个思念的角度 2025-01-15 09:46:50

Xcode 使用 Core Data 为基于文档的应用程序创建的模板非常适合您所描述的内容。您可能需要包含更多信息,但要检查的一件事是 Info.plist 中的文档类型是否正确。以下是开箱即用的值。当您在项目视图中选择目标时,Xcode 中的“信息”选项卡下还有一个图形编辑器。

尝试创建一个新项目,并选中“核心数据”和“基于文档的应用程序”(Xcode 4.3),并检查是否工作正常。如果是这样,那么您的配置中的某些内容已更改为二进制而不是 XML。

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>binary</string>
        </array>
        <key>CFBundleTypeMIMETypes</key>
        <array>
            <string>application/octet-stream</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Binary</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSTypeIsPackage</key>
        <false/>
        <key>NSDocumentClass</key>
        <string>Document</string>
        <key>NSPersistentStoreTypeKey</key>
        <string>Binary</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>sqlite</string>
        </array>
        <key>CFBundleTypeMIMETypes</key>
        <array>
            <string>application/octet-stream</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>SQLite</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSTypeIsPackage</key>
        <false/>
        <key>NSDocumentClass</key>
        <string>Document</string>
        <key>NSPersistentStoreTypeKey</key>
        <string>SQLite</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>xml</string>
        </array>
        <key>CFBundleTypeIconFile</key>
        <string></string>
        <key>CFBundleTypeMIMETypes</key>
        <array>
            <string>text/xml</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>XML</string>
        <key>CFBundleTypeOSTypes</key>
        <array>
            <string>????</string>
        </array>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSTypeIsPackage</key>
        <false/>
        <key>NSDocumentClass</key>
        <string>Document</string>
        <key>NSPersistentStoreTypeKey</key>
        <string>XML</string>
    </dict>
</array>

The template that Xcode creates for a document based app with Core Data works perfectly for what you're describing. You may need to include a bit more info, but one thing to check would be that the document types in your Info.plist are correct. Below are the out of the box values. There's also a graphical editor in Xcode for this under the Info tab when you have your target selected in the project view.

Try creating a new project with Core Data and Document Based Application checked (Xcode 4.3) and check to see if that works fine. If it does, then something in your configuration has changed to make it binary instead of XML.

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>binary</string>
        </array>
        <key>CFBundleTypeMIMETypes</key>
        <array>
            <string>application/octet-stream</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Binary</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSTypeIsPackage</key>
        <false/>
        <key>NSDocumentClass</key>
        <string>Document</string>
        <key>NSPersistentStoreTypeKey</key>
        <string>Binary</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>sqlite</string>
        </array>
        <key>CFBundleTypeMIMETypes</key>
        <array>
            <string>application/octet-stream</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>SQLite</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSTypeIsPackage</key>
        <false/>
        <key>NSDocumentClass</key>
        <string>Document</string>
        <key>NSPersistentStoreTypeKey</key>
        <string>SQLite</string>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>xml</string>
        </array>
        <key>CFBundleTypeIconFile</key>
        <string></string>
        <key>CFBundleTypeMIMETypes</key>
        <array>
            <string>text/xml</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>XML</string>
        <key>CFBundleTypeOSTypes</key>
        <array>
            <string>????</string>
        </array>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSTypeIsPackage</key>
        <false/>
        <key>NSDocumentClass</key>
        <string>Document</string>
        <key>NSPersistentStoreTypeKey</key>
        <string>XML</string>
    </dict>
</array>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文