NSInvalidUnarchiveOperationException? - swift

The current app I have been working on has been running fine with no issues and suddenly, what seems like out of the blue as I hadn't made any changes, crashes at launch with an NSInvalidUnarchiveOperationException.
I made zero code changes and the only thing I did was to run the app on my Mac to see how it would look on MacOS. I then ran it again on my iPhone and that's when the problem started to occur. I use CoreData and CloudKit so decided to delete all data to see if that would solve the issue (not thinking it would based on the console log) and it still crashes.
The console states the following:
Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: '*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (NSFontDescriptor) for key (UIFontDescriptor) because no class named "NSFontDescriptor" was found; the class needs to be defined in source code or linked in from a library (ensure the class is part of the correct target). If the class was renamed, use setClassName:forClass: to add a class translation mapping to NSKeyedUnarchiver'
The thing is, although I use attributed strings I clearly haven't created a class named NSFontDescriptor. NSFontDescriptor is part of the SDK so I have no idea what's going on and how to fix this issue.
Any help would be much appreciated.

Related

NSUnknownKeyException? statusBarManager

I'm getting this error whenever I run my app and then the app crashes.
Thread 1: "[<UIApplication 0x161704080> valueForUndefinedKey:]: this class is not key value coding-compliant for the key statusBarManager."
I've tried googling this and it seems people have had the problem before, but either I don't understand the solution whatsoever, or the solution they present doesn't work for me. Any ideas?
Also here are the files for the project in google drive https://drive.google.com/drive/folders/1TzQgwC_CgEC_wertNmyF0ZrL_vKFgILS?usp=sharing

Can't decode Swift object in framework

I had a perfectly working app. I wanted to modularize my app because I envision needing bits and pieces of it in other apps. So, I created two frameworks. The two frameworks build fine and my app with the two frameworks embedded in it also builds fine.
My problem comes when I try to unarchive data which has a class that is now in one of my frameworks. I get this error:
reason: '*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (myProjecy.MyObject) for key (NS.objects); the class may be defined in source code or a library that is not linked'
In my app I can create instances MyObject fine. All the required methods in the framework are either open or public (or the app wouldn't even build).
What an I missing?
The class in the framework is in Swift and the class trying to unarchive it in is Obj-C. I'm using Xcode 9.
Thanks.
OK. I found the problem. Re-visiting this post led me to a solution.
In my case, because the original object was archived while still part of the app and my app specified to use module name then the object was archived with the app's module name. Now, the unarchiver is trying to use the module name in the framework which is what leads to the problem.
So, I basically had to sprinkle a few of these:
NSKeyedUnarchiver.setClass(ClassName.self, forClassName: "AppModule.ClassName")
NSKeyedArchiver.setClassName("AppModule.ClassName", for: ClassName.self)
And everything works fine!
Without this code the the unarchiver tries to use "FrameworkModule.ClassName".

iOS Framework not able to create object

I have created a iOS framework in which I only have a UIView Class (let say X) in which I have declared some datasource and delegate methods.
Now when I am using the framework in a project and try to create a object of X, it gives me following error:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_X", referenced from:
objc-class-ref in ViewController.o
Now if I take a UIView in XIB and change its class to X and connect it to an outlet and then setDelegate and setDatasource it throws an exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[UIView setDataSource:]: unrecognized selector sent to instance 0x756f670
if I don't do the above two steps. it builds and runs fine.
I hope I am clear with question. Thanks for any help in advance.
As for 1:
The reason is that the framework is not built for the iPhone Simulator. I had a similar issue with CocosDenshion, documented in this SO Question of mine (someone didn't like it though, for some reason).
The easiest solution is put your project and your framework into an Xcode Workspace and Xcode will build the framework for the iPhone Simulator as and when required. If you don't want to do that then follow the instructions in the SO question linked above.
As for 2:
You need to provide the methods specified; it looks like you changed a UITableView-based class and changed it to a UIView-based class, which won't work. Derive the new class from UITableView and things should start rolling again.

Sencha Touch + DeftJS

I'm trying out the DeftJS framework in a Sencha Touch application.
But i'm having troubles implementing the newest version (0.6.5)
when it goes over the following lines:
classDefinition = Ext.ClassManager.get(this.getClassName());
where
this.getClassName() outputs "TimeSheetApp.store.TotalActualStore"
so the following line
if (classDefinition.singleton)
throws this exception:
Uncaught TypeError: Cannot read property 'singleton' of null
Any idea what i'm doing wrong here?
The issue here is that the specified class has either not been loaded or does not exist.
Double-check that the class name you've specified is exactly correct and that it has been loaded via Ext.require() in your primary JavaScript file before Ext.onReady(), or via the requires: annotation on your root Sencha Touch application class.
Even as the author of the Deft JS framework, I ran into this problem this week, too. The error being thrown as of v0.6.5 is not particularly helpful. I filed an issue on GitHub capturing this problem, so you can track progress there:
https://github.com/deftjs/DeftJS/issues/16
We will be adding better error handling and notification in v0.6.6.
In the meantime, correcting the name or adding the missing class requirement should get you going again.
Thanks for checking out Deft JS!

Error compiling for unit test using google toolbox for mac

Hi my application runs fine but when I try to run the unit tests I am getting this error...
2010-10-19 00:27:49.919 AssignmentUnitTest[27988:903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'*** -[NSURL initFileURLWithPath:]: nil string parameter'
Irony is I have searched the whole project & I dont have any similar line of code that uses **[NSURL initFileURLWithPath:]**
I have pretty much wasted half of my day on it without any success.
I am using coredata in the project & below is the screen shot with stack trace.
Can anyone please guide me to the right direction.
Thanks
**EDIt : ** The solution to this problem is to add not only the .xcdatamodel file but the root file .xcdatamodeld. Core Data was having trouble finding my model so was displaying this error. Hope it helps somebody someday.
Read the call stack in your screenshot. It says your managedObjectModel method sent [NSURL fileURLWithPath:], and that called initFileURLWithPath:. So, find the point where you sent [NSURL fileURLWithPath:] and fix your argument to that message.
The argument you passed being invalid suggests that either you passed nil for the path (perhaps you tried to find the file in your bundle but it isn't there or has a different name than you looked for), or you passed a pointer to an object that isn't a string (perhaps you had a string but under-retained it and a different object was created in its place).
There is a bug in some version(s) of the SDK that broke exception handling in the simulator.
Can you run the tests on a device?