问题描述
我在更改项目名称后遇到了问题(我认为)的命名空间。这是错误:
I am having issues with (I think) the namespace after changing the project name. Here is the error:
有一个类似的问题,但这是指iOS。对于Mac,只需更改显示包名称
将不会更改显示在dock中图标下的名称。
There is a similar question addressed here, but this is referring to iOS. For Mac, simply changing the display bundle name
will not change the name displayed under the icon in the dock.
将项目名称从Apple更改为Pear后,
当从CoreData获取文档
对象时遇到问题:
After changing the project name from "Apple" to "Pear",I am having issues when getting Document
objects from CoreData:
// Document
@objc(Document)
class Document: NSManagedObject {
@NSManaged var content: NSAttributedString
}
文档的 content
包含 SpecialTextAttachment
s。
// SpecialTextAttachment
class SpecialTextAttachment: NSTextAttachment {
//
}
打印文档的内容时,上面提到的错误。我如何将 Apple.SpecialTextAttachment
转换为 Pear.SpecialTextAttachment
?看起来我需要转换它之前,我通过数组 Document
s,因为只是引用 Document
类导致崩溃。我也无法为此类创建另一个项目,如所示。
When printing the Document's content, it gives me the error addressed above. How would I go about converting Apple.SpecialTextAttachment
to Pear.SpecialTextAttachment
? It seems like I need to convert it before I iterate through the array of Document
s, because just referring to the Document
class causes a crash. I also cannot create another project simply for this class as suggested 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]
}
推荐答案
所以在 init()
我的类,其中包含所有的方法来处理CoreData的数据,我放置了以下代码:
So in init()
of my class which contains all the methods for handling data from CoreData, I placed the following code:
class CoreDataHelper {
init() {
NSKeyedUnarchiver.setClass(SpecialTextAttachment.self, forClassName: "Apple.SpecialTextAttachment")
}
}
这会将任何 Apple.SpecialTextAttachment
转换为 Pear.SpecialTextAttachment
在任何即将到来的操作中, SpecialTextAttachment
可能会出现。
This will convert any Apple.SpecialTextAttachment
to Pear.SpecialTextAttachment
in any upcoming operations in which SpecialTextAttachment
may come up.
这篇关于重命名OSX的Xcode项目后的NSKeyedUnarchiver错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!