4

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!

1 Answer 1

11

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; 
Sign up to request clarification or add additional context in comments.

9 Comments

how can i import the compiler generated header file?
Like importing any other file #import "YourProductName-Swift.h". YourProductName will be same as app target name
i did import "#import "MyProjectName-Swift.h" but it shows me an error "file not found".
Is your app target name is MyProjectName?
yes, my project and targer both have the same name as MyProjectName
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.