Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing UIWindow from AppDelegate.swift in Objective-C file

Tags:

ios

swift

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!

like image 218
iCoder86 Avatar asked Dec 19 '22 12:12

iCoder86


1 Answers

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;
like image 125
Anil Varghese Avatar answered Apr 01 '23 04:04

Anil Varghese