First of all I know about this: How do I get a reference to the app delegate in Swift?
Second, what I need to do is to access the appdelegate properties in the Swift side of a mixed app.
Basically,
1- I have a project which is started as an Objective C project. This means AppDelegate is defined in the Objective C side.
2- I have swift code working fine, I have a bridge header and I can reference things form either side on the other side.
3- Here is the problem: To reference the appdelegate in my Swift code I need to #import "AppDelegate.h"
in my bridging header. But for other reasons, I also need the AppDelegate.h to import the SWift header ( PROJECT-Swift.h
). This creates a reference loop.
Is there a way to avoid this reference loop? and still access AppDelegate properties?
EDIT: An additional complication that I did not mention in the first edition of the question is that, the AppDelegate property that I want to expose to Swift code, is actually of a Type declared in the Swift side. So I need to declare it in the AppDelegate.h
and to be able to do that, I need to import the -Swift.h
header in my AppDelegate.h
.
To make it more clear:
KB
is a public class
defined on the Swift side.
AppDelegate has a property like: @property (strong) KB *appkb;
I need to get a hold of ((AppDelegate*)UIApplication.SharedApplication()).appkb