iCoder86
iCoder86

Reputation: 1895

Accessing UIWindow from AppDelegate.swift in Objective-C file

I am working on swift project where I need to use my old Objective-C code.

I did managed to create -Bridge-Header.h file and it works for me.

now in my Objective-C code I need to refer UIWindow from AppDelegate.swift,

Can any one has done this before?

Please guide me!

Upvotes: 4

Views: 4497

Answers (1)

Anil Varghese
Anil Varghese

Reputation: 42977

First to access the Swift classes in ObjC ,you could import the compiler generated header file to expose those files to ObjC. It would be like ProductModuleName-Swift.h.(This file doesn't really exists to see,but Xcode will automatically create it for you)

#import "YourProductName-Swift.h"

Then you can access the window property in the app delegate from the ObjC file like

AppDelegate *delegate =  [[UIApplication sharedApplication]delegate];
UIWindow *window = delegate.window;

Upvotes: 11

Related Questions