Building pure Swift Cocoa Touch Framework

前端 未结 5 944
南笙
南笙 2020-12-05 02:18

I\'m exploring Swift with Xcode-6 and so far so good although I think the new collections need a little bit of work as I\'ve managed to break the compiler a few times.

相关标签:
5条回答
  • 2020-12-05 02:49

    Assuming you are creating a truly pure Swift module, you must disable the Objective-C Compatibility Header and any generated interface headers so the compiler doesn't go off assuming it can find an Objective-C module for the framework. enter image description here

    Do Not remove your public framework header. You'll get a module-map warning at link time if you do.

    0 讨论(0)
  • 2020-12-05 02:55

    EDIT (7/27/2018)

    The information in the answer below may no longer be accurate. Your mileage may vary.


    I sat down with an engineer and asked this exact question. This was their response:

    Xcode 6 does not support building distributable Swift frameworks at this time and that Apple likely won't build this functionality into Xcode until its advantageous for them to do so. Right now, Frameworks are meant to be embedded in your app's project, rather than distributed. If you watch any of the session videos or see the sample projects, this is always the arrangement. Another reason is that Swift is very new and likely to change. Thus your Swift-based framework is not guaranteed to work on the platform you originally built it on.

    Slight Update

    The engineer mentioned that it's not impossible to make a framework for distribution, just that it's not supported.

    0 讨论(0)
  • 2020-12-05 02:55

    I was able to get past the error by going to the target for the framework and on the Build Phases tab under Headers, remove the MyFramework.h file

    However I was getting the "Underlying Objective-C module not found" error when I was using a framework to share code between a containing app and an app extension, both of which were pure Swift.

    Image showing MyFramework.h for the MyFramework target on the Build Phases tab under Headers

    0 讨论(0)
  • 2020-12-05 02:57

    I think it's a bug in XCode 6, or that Apple does not allow archiving the Framework from XCode while in beta.

    If you compile to profile XCode generates the framework correctly. (See the Release folder created in DerivedData)

    0 讨论(0)
  • 2020-12-05 02:59

    You might find this useful: Creation of pure swift module

    In short: it's possible to make static framework, but there is one issue: it doesn't work in end user' project if "ProjectName-Swift.h" header included.

    But, it works fine if you use only swift.

    0 讨论(0)
提交回复
热议问题