Thanks a lot for the tips @sjr.
I did manage to get it to work so I am posting here hoping others will find this useful.
After a bunch of experimentation this is what worked for me:
-
Add the SDL sources to your include path so you can import "video/uikit/SDL_uikitappdelegate.h"
. You can do this the same way you add the SDL Public Headers to the include path as described in the SDL ios readme.
-
Create a bridging header between swift and objc. This can just be a simpler header file that just does the following:
#ifndef SwiftObjcBridgingHeader_h
#define SwiftObjcBridgingHeader_h
#import "video/uikit/SDL_uikitappdelegate.h"
#endif /* SwiftObjcBridgingHeader_h */
After you create it, go to the “Build Settings” tab, search for “Objective-C Bridging Header” and set the path to your bridging header (e.g., YourProjectName/YourProjectName-Bridging-Header.h
).
- Create a category in objc to pass on the name of your new app delegate. Here is how I wrote mine:
#import <Foundation/Foundation.h>
#import "video/uikit/SDL_uikitappdelegate.h"
#import "YourProject-Swift.h" // This is an xcode generated header so you can import swift classes in objc
@interface SDLUIKitDelegate (Extensions)
@end
@implementation SDLUIKitDelegate (Extensions)
+ (NSString *)getAppDelegateClassName {
return NSStringFromClass([AppDelegate class]);
}
@end
I initially tried making this in swift and it didn’t work, but when I made it in objc it did. Given this is such trivial code I am ok with it being in objc but I wanted the AppDelegate to be in Swift since I am more experienced with that.
- Create your new AppDelegate.swift and implement it as such:
import OSLog
import Foundation
import UIKit
class AppDelegate : SDLUIKitDelegate
{
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
os_log("Calling from SWIFT")
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
You should see the message logged there in your console, or alternatively (and more importantly imo) you can put a breakpoint on it to confirm it works. Your SDL code should still run as normal after.
Initially I tried writing a whole new app delegate from scratch but that was annoying, just inheriting from SDLUIKitDelegate
and overriding methods while being sure to call super.whatever
works perfectly as far as I can tell right now.
If there are any observations about my technique or anyone needs some help with this let me know. I am glad that now I can write swift code and debug it in xcode for any native ios needs I may have.