How to correct "corrupt and unarchivable nib"? - swift

I am writing a macOS app in Swift4. I'm targeting macOS 10.9, so I'm using xibs instead of storyboards.
When I try to run and open the nib via showing the window, it logs an error:
-[NSIBObjectData initWithCoder:]: corrupt and unarchivable nib file
-[MyWindowController loadWindow]: failed to load window nib file '/Users/toadzky/Library/Developer/Xcode/DerivedData/MyProject-cdudiyhqvfaauudsignqhtkqlfeu/Build/Products/Debug/My App.app/Contents/Resources/MyWindow.nib'.
The file is a xib, so i'm not sure if it's just an outdated error message. I'm subclassing NSWindowController and using the init(windowNibName:) constructor for my window controller.
I've tried restarting Xcode, cleaning and rebuilding the project, modifying the xib so xcode will rewrite it, etc. I haven't re-created it from scratch because it's a fairly complex view, and it's time consuming to redo so I'm hoping there's an alternative solution.
Update
I rebuilt the entire XIB from scratch, no copy-paste since I couldn't be sure what was wrong. Everything worked fine until I added some custom formatters using interface builder. Then it broke in the same way. I took them off and it worked again.
Two hours later, I added the custom formatters back and it works fine.
I'm leaving the question open in the hopes that someone will be able to provide some troubleshooting advice for when Xcode decides to arbitrarily not work for a while.

Make sure that in your init method you are initializing the super class and returning self.

Related

iPhone: View loading but not view controller

I had an issue with a project getting the dreaded "Error: cannot attach to process ID 0". Tried everything I could and it wanted nothing to do with me. So I started a new project and readded all my files and frameworks and what not in it.
Now my project runs. It shows me the first screen in my storyboard. However, the ViewController class attached to the window is not getting loaded and neither is the NavController class attached to my navigation controller. I reset the class in the Identity Inspector but still it wants nothing to do with me.
I added some NSLog(#"Test"); in the viewDidLoad methods of both my classes and they're not getting called. However, I added that same line to the AppDelegate applicationDidFinishLoadingWithOptions and that one did pop up in the debugger.
Any ideas?
I met that issue before, maybe it is some bugs of Xcode, the following steps works for me:
quit simulator
clean project
delete project's derived data
quit Xcode
restart Mac if you like
then reopen Xcode and everything is ok.

iPhone app opens to black screen after refactor proj name in xCode 4

Guys, i wonder if any one can help - My project was fully working in both the simulator and on a device, however, i renamed the project in xcode 4 (double clicking at the root of the project navigation pane, it was happy to rename any references - but now when i launch the app it only opens to the main window (yes it has outlets, all have outlets etc etc),
no code in the app delegate stops at a break point (even in didFinishLaunchingWithOptions)
so unsure what i could have missed, i have looked at other answers and everyone writes and says "missing outlet" etc.
I have dragged some backed up version of the app delegate that used to work and no difference, what could i be missing.
I do have source control, however currently in the process of merging from VSS to GIT.
thanks
lee
Check your Info.plist for what it uses as it's Main Nib File. Perhaps something changed there? Also, within the nib file itself you might have problematic connections to classes that are still named with the old name.

iPad SDK: Why are my nib changes not showing?

I've made an iPad app. Now, I'm changing some UI elements in the NIB. When I run the app in the simulator none of my changes appear.
I've tried touching the project before building. Nothing is working.
Can anyone shed some insight?
It seems you are not loading the correct NIB file, or more probably you have for gotten to make the right connections in you NIB file with the owner file.
If none of these are the case we are going to need some code that shows where you load you nib and/or a NIB we can inspect ourselves. :)
Try this:
Clean the target (⇧⌘K)
Delete the app from the Simulator
Build & Run as normal.
Make sure you save the changes in Interface Builder. I've found that on occasion I've forgot to save changes there, with predictable results.
In the Simulator menu, select "Reset Content and Settings…" which wipes out anything that was there previously. Xcode saves time by not installing anything it thinks is already there. This usually works fine, but occasionally can lead to out-of-date resources not being updated.

XIB File Not Loading Properly In Interface Builder

I was creating a new View-based Application in XCode, adding some outlet and actions, using the IBAction and IBOutlet tags, into the automatically created controller view header file. I then double clicked the 'project_name_ViewController.xib' to launch the interface builder.
However the outlets and actions did not appear in interface builder. The only way I could get them to appear was the close the xib file and reopen it through file -> open command in Interface Builder it's self.
I recently upgraded to Snow Leopard, before that I never had this problem.
Has anyone else come across this?
Xcode is full of strange bugs. I always follow my 15 step arcane black magic ritual before I make an ad-hoc or release build. Any time something like your problem happens, I put it down to the flying monkeys twisting bolts somewhere in Xcode and restart the program (sometimes the computer). That generally fixes it.
Of course with outlets and actions, it's easy to forget to save the source header before you swap over. Make sure to save and build. Errors in the source can stop them from showing up in IB too.

Interface Builder caching bad data (voodoo)

Sometimes IB will hold onto old or bad references, and I cannot seem to remove or edit them.
EDIT I have made this a wiki question with the intention of gathering more data on the phenomenon. Answers involving situations where other coders have encountered this are welcome.
This happened to me again last night with a table controller. When I created a spike project to try and reproduce the error, the system worked the way I anticipated. Then back in the actual project the bad behavior continued, even if I remove the xib file and all controllers involved.
Creating a whole new project with none of the original (problematic) xib and nib files worked correctly.
This question is not about the specifics of this incident but about this type of incident in IB.
Does anyone know more about this type of bad IB behaviour, and possibly a more stylish way to to eliminate it than nuking the project?
Note, removing the offending IB files and recreating them in the same project has not solved this for me in the past, only whole new projects.
Answers regarding examples of when/how this glitch has been observed/created are welcome as well.
I fixed this type of caching problem by clicking File > Read Class Files ... and pointing IB to my class files. Bingo, it read them fine, and everything worked. :-)
The only real suggestion I have is to file a bug report at http://bugreporter.apple.com/ with a reproducible project as the attachment; in my experience Apple do look at these things. That said, you say that re-creating the XIB in the same project didn't fix the bug. What about replacing the other end of the link; i.e. re-create the header file and use that new header with the existing XIB? Perhaps that's sufficient to prod IB into updating its model.
I just had a project where this happened and I was banging my head trying to get it to update properly in IB 3.2 (732). I really did not want to redo the xib from scratch. I tried drag/drop of the *.h files, restarting, reloading everything and it didn't work. I also tried File->Read Class Files which didn't work. Strangely though, File->Reload All Class Files worked like a charm.
I find that File > Read Class Files fixes it for a single nib file, however the nib doesn't remain in Sync with any future changes and the fix doesn't apply to any other files in the project either.
Restarting and/or clean building didn't help either, but new projects are fine. This has been happening to me in Xcode/IB ver 3.2.2 - so far the only solution has been rebuilding the code in a new project.
Maybe not the answer you want, but here it is: Do not use IB! :-)
I had troubles using it too, even when reproducing exactly the steps as described in some Apple docs, trying multiple times from scratch. So after 3 days I just gave up and started doing everything programmatically, implementing my program in half a day. I have never looked back since. I only launch IB occasionally to look at sizes, so I can feed them into my code.
It will probably be less easy to update my GUI over time, but if your story is a real recurrent problem, I'm glad I parted ways with the beast!
When you say old or bad references, do you mean it is trying to link UI elements to outlets or actions in a class that no longer exist? If that is the case then go to the connections panel (cmd-5) and select the object in your nib file. It should show you all the connections. Any where the text is greyed out and have an exclamation mark should be deleted (hover over and click the x).
In IB, you are only connecting to a "promise" of what your class will be like when the app launches. IB normally only lets you connect stuff that can fulfil that promise, but if you change the header in Xcode there's nothing IB can do about it besides warn you.
Try making a clean build of the code and then see if the old references remain in the xib
You don't say if the problem has persisted across restarts, so I think it might be this issue: There is a rare bug in Xcode's build process where sometimes old versions of output files are stuck in the /tmp folder and won't get updated. IIRC, the easiest solution is to clean the target and reboot your computer.
Are you saving the header files? Interface Builder parses the content of your header files on disk, not the unsaved files in Xcode's editor. If you add an outlet to a header file, and switch back to IB without saving first, IB won't see the new outlet.
I had exactly the same problem with IB when I created a new project out of an old one.
I can synchronize IB with the new .h files but IB still gave the removed references (from the old project) when I right-clicked the object ( the class name "MainController" was the same from the old to the new ) even though those references did not exist in the updated code at all.
"You don't say if the problem has persisted across restarts, so I think it might be this issue: There is a rare bug in Xcode's build process where sometimes old versions of output files are stuck in the /tmp folder and won't get updated. IIRC, the easiest solution is to clean the target and reboot your computer." I tried to clean the target but it did not work.
However, once I deleted the MainManu.xib and created a new one (there would be a bit work to design the interface by hand), the old references were gone.
I experienced the same problem. It happens when I open a project made with old Xcode version. Interface Builder does not sync correctly with Xcode. Yes, I can manually update the IB cache with the 'File->Read Class Files...', but even with this method garbage remains. I mean old IBOutlet and IBAction still shows up.
Just had this type of incident and fixed it by using XCode's refactoring to rename classes to different names. Seemed to get stuff restarted.
Reading the problematic class file again has solved this problem for me.
QUICK EASY SOLUTION: - no computer restart, no new project required . . .
Unfortunately none of the suggestions in this post have fixed this issue for me (aside from restarting my computer and then starting a whole new xcode project)
MY SOLUTION...
Anyway, the only other quick fix (that works for me with Perfoce at least), is to back out (revert) my changes in my revision control system. We are using Perforce, and this seems to work just fine.
I didn't have to create a whole new xcode project, no restarting the computer, no restarting xcode even, no manual deleting of files or references, no re-references classes, no click and drag garbage to deal with, no manual settings changes, etc.
DOWNFALL...
If you are walking all around xcode and the IB for a while, and have made a lot of changes, and then all of a sudden the issue occurs... you will then of course lose everything in the files you revert... QQ
glhf
-eric
SIDE NOTE...
this is a pretty bad bug, and definitely consumes a lot of time, especially if its your first time coming across this issue (and I'm sure everyone here realizes, that time is essential to a developer). This is the first time I've ever been disappointed with apple/obj c/xcode (started 2 months ago), and i sense this won't be the last : /