NSKeyedUnarchiver error after renaming Xcode project for OSX

后端 未结 3 1499
面向向阳花
面向向阳花 2021-01-14 22:58

I am having issues with (I think) the namespace after changing the project name. Here is the error:

Terminating app due to uncaught exception \'NSInva

相关标签:
3条回答
  • 2021-01-14 23:49

    It happens because your *.xcodeproj (project.pbxproj) by default use $(TARGET_NAME) for Product Name and $(PRODUCT_NAME) in another fields. For example, Product Module Name by default setted as $(PRODUCT_NAME:c99extidentifier). All you need is replace all PRODUCT_NAME to TARGET_NAME in Build Settings.

    0 讨论(0)
  • 2021-01-14 23:50

    I sort of gave up on this and continued to go with my decision to rename the project.

    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")
        }
    }
    

    This will convert any Apple.SpecialTextAttachment to Pear.SpecialTextAttachment in any upcoming operations in which SpecialTextAttachment may come up.

    0 讨论(0)
  • 2021-01-14 23:53

    You can change the displayed name of the app on OS X without changing the bundle name. The procedure is a little different than on iOS.

    First, if you haven't already, you need to create an InfoPlist.strings file for your app. Use the “OS X > Resource > Strings File” template:

    Then localize InfoPlist.strings to the Base localization:

    In the strings file, assign your new name to the CFBundleName key, like this:

    CFBundleName = "Pear";
    

    If you have set the CFBundleDisplayName key in Info.plist, you should assign your new name to CFBundleDisplayName in InfoPlist.strings. If you haven't set the CFBundleDisplayName key in Info.plist, you don't have to set it in InfoPlist.strings.

    That is sufficient to make your app show its new name in its menu bar and in the Finder. However, your old name still appears, hardcoded, in several places in your MainMenu.xib or Main.storyboard. You can find them by choosing menu bar > Find > Find… (default shortcut: ⌘F) like this:

    You need to change these to “Pear”. (Technically you don't have to change the “Apple” menu title, because AppKit will change it at runtime to the localized string in InfoPlist.strings, but it's simpler if you just change all instances of “Apple” to “Pear”.)

    If you have actual localizations to other languages, and you want the app name to be localized, you'll need to localize InfoPlist.strings to each of your localizations and set the CFBundleName (and maybe CFBundleDisplayName) in each of them.

    0 讨论(0)
提交回复
热议问题