Why does my Swift bundle get the wrong principal class? - swift

I made a bundle target, and its Info.plist file specifies that a very specific class (let's call it PrincipalClass) should be its principal class. This class was written in Swift and has the #objc attribute. The Info.plist file is correctly copied over to the bundle, and I have cleaned and rebuilt the project multiple times already.
However, when I load the bundle from my Swift framework, its principal class is a different class (let's call it NotPrincipalClass). It was not marked #objc, and in fact, it should be internal to the bundle. I checked bundle.bundleURL in the debugger, and the Info.plist file in the bundle does say that it should be PrincipalClass; but when I check bundle.infoDictionary, the NSPrincipalClass attribute reads NotPrincipalClass as a string! (The info dictionary also contains several keys that were not specified by the Info.plist file, like DTCompiler and such.)
If I entirely remove NotPrincipalClass, I get another internal class instead, which is still totally not my principal class.
I checked the build logs thoroughly and I saw no mention of NotPrincipalClass, except when it got compiled.
What could cause this? What can I do to solve it?

Somehow, using its qualified name instead ("PlugInNamespace.PrincipalClass") solved the problem, but this has me very skeptical because I have another plugin that does not requires this.

Related

TypeAlias a class contained in NSKeyedArchiver file

My app uses a file created with NSKeyArchiver, it has a reference to an object that is contained in an external Framework. The external Framework is no longer is available in the app Xcode project. So when I attempt to load the archive file, the app will crash when attempting to resolve the type of this object. i.e MyMobileKit_Token
I was wondering if it's possible to create a 'local' instance of the object type in the app, then using the typealias fool the unarchive operation to reference the local type i.e Token
Or would I have to create a new 'proxy' Framework project with this one class and add the proxy framework to my app project keeping the naming of the framework and class exactly the same.
Any ideas?
Thanks
Aha, I found the answer. I created a class called Token with the same properties in the framework. Then I added the following line before opening the archive file:
NSKeyedUnarchiver.setClass(Token.self, forClassName: "MyMobileKit.Token")
Seemed to work out.

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".

Swift Namespacing Issue

I have created a class named Bundle, which I'd really like to remain named that way, as it perfectly describes what it's for in my project.
Now, I'm using Swift's Bundle in some code and now those names are conflicting. I had this issue before when I created the class Set. I was able to solve that by putting Swift.Set when I wanted to use the standard Set class, as I found in this answer on exactly this matter.
I also tried to apply that solution my Bundle problem, but Xcode complains:
Module 'Swift' has no member named 'Bundle'
Any idea why it does work for Set, but not Bundle?
Thanks!
Bundle is defined in the Foundation library, not in the Swift standard
library:
let mainBundle = Foundation.Bundle.main

Bundle Identifier Changed Core Data Lost

I changed a project from Objective-C to Swift and created a whole new project when I did this. I have an app in the AppStore and wanted to send an update instead of releasing a new app.
I understand that my Bundle Identifier needs to be the same when updating an app. When preparing the app for release, I changed my Bundle Identifier to match my app in the AppStore - since I started with a new project - and in the process my Core Data file seems to be missing. If I change my Bundle Identifier how do I keep access to Core Data?
This took me a while to figure out but here is how I fixed the issue.
Change your product name under Build Settings -> Packaging -> Product Name to the desired product name. This will change you Bundle Identifier to the desired name.
Clean your project by selecting Product -> Clean.
Select your CoreData model in the project navigator and then select the "Data Model Inspector" in the Inspector tab. Change the project name under class to the new class name. I got stuck here since I did not know Spaces, dashes, . are all replaced by underscores. You can see that my Product Name is FLO-Cycling and the CoreData class is FLO_Cycling.
If you have imported the Swift bridging header file anywhere make sure to update it.
I hope this can help someone.
Take care,
Jon

ATG browser components is not available

I want to create new companent in ATG. And if I forward to Browser Companent page, then I have 404 error. How I can fix this?
I assume that you have created a new component by creating a .properties file. The things to look for are
Is the file in an appropriate config layer? i.e. is it in a location on the configpath, such as the config directory of a module, or the localconfig directory of a server, where the application expects to look for .properties files?
Is the file a valid .properties file and properly formatted?
Is the class mentioned in the $class property correct, valid and fully qualified (package name and class name)
Has the named class been compiled successfully?
Is the named class available on the classpath? i.e. is it in the classes.jar of a module or in the classes directory (if that is how the module's class path has been defined?
Is the class a valid JavaBean - particularly, does it have a no-argument constructor?
Have you compiled, built and assembled your ATG application since creating this new component?
Have you restarted your ATG application since creating this new component?
Assuming this is all correct and yet you still cannot see your component, the next step is to troubleshoot why it is not visible.
Is the path to your component you are using in the dyn/admin component browser correct?
If the path is correct, and you still see an error in the browser, then take a look at the server logs (for around the time you first tried to access the component) - you might see an error or a sequence of errors telling you why the server could not instantiate the component
Can you go to the containing folder and see if the component is listed there - though it is OK if you cannot because it may not have been started if nothing is referencing it
Can you see your component in the ACC. Start the ACC, and go to View Components by Path and navigate to were you think your component should be. Can you see it there? If so, it means that your properties file is OK.
In the ACC, When you click on the puzzle-piece icon that represents your component, does it show it as being an instance of your class or as an instance of Object. If Object, it means that it cannot determine the class of the component
In the ACC, double-click the component and try to start it. Keep looking at the server logs as you do so
This should help you get to the bottom of things.