2015-12-15 99 views
2

我在更改项目名称后遇到(我认为)命名空间问题。以下是错误:为OSX重命名Xcode项目后出现NSKeyedUnarchiver错误

Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: '* -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (Apple.Document) for key (NS.objects); the class may be defined in source code or a library that is not linked'

有一个类似的问题解决here,但这指的是iOS版。对于Mac,只需更改display bundle name将不会更改在扩展坞图标下显示的名称。

从“苹果”到“梨花”, 改变我有问题,从CoreData越来越Document对象时,项目名称后:

// Document 
    @objc(Document) 
    class Document: NSManagedObject { 
     @NSManaged var content: NSAttributedString 
    } 

文档的content包含SpecialTextAttachment秒。

// SpecialTextAttachment 
    class SpecialTextAttachment: NSTextAttachment { 
     // 
    } 

当打印文档的内容时,它给了我上面提到的错误。我将如何去转换Apple.SpecialTextAttachmentPear.SpecialTextAttachment?看起来好像我需要在迭代Document之前对其进行转换,因为只涉及到Document类会导致崩溃。我也不能像建议here那样简单地为这个班级创建另一个项目。

// in ViewController 
    func getDocuments() { 
     let fetchRequest = NSFetchRequest() 
     fetchRequest.entity = NSEntityDescription.entityForName("Document", inManagedObjectContext: managedObjectContext!) 
     fetchRequest.fetchBatchSize = 20 
     let docs = (try? managedObjectContext!.executeFetchRequest(fetchRequest)) as! [Document] 

    } 

回答

1

我有点放弃了这一点,并继续与我决定重命名项目。

所以在我的类,它包含了所有从CoreData处理数据的方法的init(),我把下面的代码:

class CoreDataHelper { 
    init() { 
     NSKeyedUnarchiver.setClass(SpecialTextAttachment.self, forClassName: "Apple.SpecialTextAttachment") 
    } 
} 

这将任何Apple.SpecialTextAttachment转换为Pear.SpecialTextAttachment任何即将到来的操作,在此SpecialTextAttachment可能会向上。

1

您可以在OS X上更改应用程序的显示名称,而无需更改软件包名称。该过程与iOS上的有所不同。

首先,如果你还没有,你需要为你的应用程序创建一个InfoPlist.strings文件。使用“OS X>资源>字符串文件”模板:

Creating InfoPlist.strings

然后定位InfoPlist.strings到基本定位:

Creating InfoPlist.strings Base localization

在字符串文件,指定你的新名称CFBundleName键,如下所示:

CFBundleName = "Pear"; 

Setting CFBundleName in InfoPlist.strings

如果您已将CFBundleDisplayName密钥设置为Info.plist,则应将您的新名称分配给CFBundleDisplayName,InfoPlist.strings。如果您尚未在Info.plist中设置CFBundleDisplayName密钥,则不必将其设置为InfoPlist.strings

这足以让您的应用程序在其菜单栏和Finder中显示其新名称。但是,您的旧名称仍会出现在硬编码中,位于您的MainMenu.xibMain.storyboard的几个位置。您可以通过选择菜单栏中找到他们>查找>查找...(默认快捷键:⌘F)是这样的:

finding Apple in MainMenu.xib

你需要这些改变为“梨”。(从技术上讲,您不必更改“Apple”菜单标题,因为AppKit会在运行时将其更改为InfoPlist.strings中的本地化字符串,但如果您只将“Apple”的所有实例更改为“Pear”,则更简单。)

如果您有其他语言的实际本地化版本,并且您希望将应用程序名称本地化,则需要将InfoPlist.strings本地化为您的每个本地化版本,并在其中每个版本中设置CFBundleName(也可能为CFBundleDisplayName)。

+0

谢谢,但是设置CFBundleDisplayName并没有改变任何东西。即使干净后。 –

+0

你不需要在Info.plist中设置CFBundleDisplayName(我不建议你这么做)。我只说你需要在你的'InfoPlist.strings' **中设置**如果你有(因为某种原因)将它设置在你的Info.plist中并且希望保持它在那里设置。 –

0

发生这种情况的原因是,默认情况下,* .xcodeproj(project.pbxproj)在其他字段中使用$(TARGET_NAME)作为产品名称,使用$(PRODUCT_NAME)。例如,产品模块名称默认设置为$(PRODUCT_NAME:c99extidentifier)。您只需要在Build Settings中将所有PRODUCT_NAME替换为TARGET_NAME即可。