Is there a Prefix Header (or something with this functionality) in Swift?

前端 未结 3 719
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 21:16

Is there a way to get the functionality of a prefix header in Swift? I don´t want to import external libs in every file where they are used.

3条回答
  •  时光取名叫无心
    2020-12-05 21:47

    1. Create a Objective-C Bridging Header file:

      [New File→iOS→Source→Header File]: Bridging-Header.h

    2. Go to this new header and import your external libs:

      @import Module1Name;
      @import Module2Name;
      ...
      
    3. Go to Build Settings, set the path of Objective-C Bridging Header:

      [Target→Build Settings→Swift Compiler - Code Generation→Objective-C Bridging Header]: $(SRCROOT)/.../Bridging-Header.h

    Then you can use external libs in every file without import code.


    References:

    • Third Party Swift Frameworks
    • Importing Objective-C into Swift

提交回复
热议问题