I have read this question and I believe my problem is different.
I have a swift class SwiftUtils.swift
that is already making calls to objective c code in my project and I have some objective c code making calls back to swift.
So I've got the bridging header stuff all working as it should.
My issue is I am building a system menu in swift and am trying to call a method in my AppDelegate like this:
@objc func createMenuItem() {
let appDelegate = NSApplication.shared.delegate as? AppDelegate
let status = NSMenuItem(title: "System Status",
action: #selector(appDelegate.showSystemStatus(_:)),
keyEquivalent: "s")
status.target=appDelegate.self
statusItem.menu?.insertItem(status, at: 0)
}
I can't get the compiler to resolve AppDelegate
on the first line of the func.
Xcode keeps telling me "Cannot find type 'AppDelegate' in scope"
My bridging header:
#ifndef Foo_Bridging_Header_h
#define Foo_Bridging_Header_h
#import <Foundation/Foundation.h>
#import "uiframework/Utils.h"
#import "AppDelegate.h"
#endif /* Foo_Bridging_Header_h */
My AppDelegate.h:
#import <Cocoa/Cocoa.h>
#import "Foo-Swift.h"
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property SwiftUtils *utils;
- (void) checkForUpdates;
+ (void) showSystemStatus;
@end