I am having issues with (I think) the namespace after changing the project name. Here is the error:
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'
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.
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
}
The Document's content
contains SpecialTextAttachment
s.
// SpecialTextAttachment
class SpecialTextAttachment: NSTextAttachment {
//
}
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]
}