[swift-users] Making Protocol Buffer objective c headers public in a Swift Framework

Victor Leong victor.leong at visiercorp.com
Mon Jan 25 17:14:40 CST 2016


Hey everyone,



I'm running into a very specific case right now and I'm wondering if anyone
has any experience with this situation.



I have a Swift project that is using a custom Swift framework that I
created. The Swift framework contains a bunch of public objects that can be
used by the projects that import this framework.



I now want to change those public objects to be defined and generated by
Google Protocol Buffers. Currently, Google's supported languages only has
Objective-C and not Swift for iOS classes so I have generated a bunch of
Objective-C classes. This is where the problem comes in.



If I want to use the Objective-C classes in Swift inside and outside of the
Framework, I need to include the generated class headers into the
framework's umbrella header. In Xcode 7.1 and above, the Swift compiler has
become very strict and will not accept non-modular headers. I've made all
the generated classes public but their imported classes all need to be
public as well which also need to be made public, and since this is the
protobuf Framework, this is made much harder.



eg. #import "GPBProtocolBuffers.h" //This has to be made public and
everything GPBProtocolBuffers.h has to be modular etc.



I need my generated Objective-C classes to be made public and accessible to
everything that imports that framework I've created. Has anyone come across
this before and have a reasonable solution?



Summary:

   - Have a Swift project using a Swift framework's public objects.
   - Changed the framework's objects to Google Protocol Buffer generated
   Objective-C classes.
   - The Objective-C classes have to be added to the umbrella header so
   Swift can access them.
   - Swift compiler complains about inclusion of non-modular classes.



Thanks,

Vic
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160125/05032833/attachment.html>


More information about the swift-users mailing list