Hello,
I spent a lot of time to find a way of using a Swift-bundle in a pure Swift Application. Finally I succeeded to avoid compile-time-linking, which caused the problems. The rules, I have to obay:
1. The principalClass in the bundle may not be declared as "final"! //Why that? Is it a bug?
2. No typecast for bundle.principalClass is allowed! //When casting, runtime-linking follows.
3. You only can use a singleton instance in the bundle - no bundle.principlaClass.init() is possible. //Is this a bug?
At the end, I could use a bundle like this:
public class XYZClass: NSObject {
public let xyzShared = XYZClass()
public func xyzRockTheBundle() {}
}
The application calls the bundle by:
import BundleName
guard let bundle = NSBundle(URL: url) else {continue} //url aus builtInPlugInsURL ermitteln
guard let bundleClass = bundle.principalClass else {return}
bundleClass.xyzShared.xyzRockTheBundle()
Is that really the right way? I did not find this in any documentation? Or is it a bug?
I'm interested in your comments.
Kind regards
Wolfgang