简体   繁体   中英

Import framework for whole project at one place in Swift?

I made an own Cocoa Touch Framework , and I want to import it only at one place in the code. In Xcode / earlier in Objective C there were a central location under Supporting Files . How does it work for Swift based project?

Create a Frameworks folder. Drag and drop your framework in it. Then create a bridging header file (easiest way to do this in Swift project is by adding an objective c class and it will ask you to create that bridging file for you). Then in your bridging header file just add

#import <YourFramework/YourFramework.h>

Then your framework classes are accessible from Swift. Hope this helps!

As I answered here: https://stackoverflow.com/a/46878808/3203441

As of Swift4:

  • Being in a Swift project
  • Want to have another Swift project globally imported (and using cocoapods)

I just managed to do that by adding the following line to my bridging header:

#import <PodName/PodName-Swift.h>

How good/bad this practise is? Not sure, but I just wanted some extensions globally available in my project. this did the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM