CoreData不将类型设置为XML [英] CoreData not setting type as XML

查看:118
本文介绍了CoreData不将类型设置为XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我有一个NSPersistentDocument的子类。我使用NSManagedObject子类/标准Core Data模型。我不做任何特殊的NSPersistentDocument或与NSManagedObject类。我只是创建一个对象(在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]];

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

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.

有什么特别的,我需要去强制它到XML?

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

我基于来自苹果的文档的理解是,在使用NSPersistentDocument子类,我不需要做设置的工作NSPersistentStore或NSPersistentStoreCoordinator。我的理解是这一切都是免费的。

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.

推荐答案

Xcode使用Core为基于文档的应用程序创建的模板数据完美地适合你描述的内容。您可能需要添加一些更多的信息,但是要检查的一件事是您的Info.plist中的文档类型是正确的。下面是开箱即用的值。

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.

尝试使用Core Data和Document Based创建一个新项目,并且在项目视图中选择您的目标。应用程序检查(Xcode 4.3),并检查是否工作正常。

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>

这篇关于CoreData不将类型设置为XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆