5
votes

I'm building a mixed language framework. I mainly have Swift files, and a few Objective-C ones.

One of the Objective-C files is a crypto class that uses CommonCrypto.

It seems that I can't import it for some reason, even though that I can import it in a Objective-C framework.

Can someone explain to me why that is?

All the other solutions that I found talk about how to use CommonCrypto in Swift when I need to use it in Objective-C in a Swift framework.

P.S:

  1. I tried adding the import in the umbrella header file like so: #import <CommonCrypto/CommonCrypto.h> the error: Include of non-modular header inside framework module 'name of header'

  2. This answer did not fix the problem: answer

1
Where are you inserting that import directive?El Tomato
@ElTomato My Objective-c class header.. also tried the umbrella headerYakir Yehuda
Please file a bug report, this is a common problem and Apple has been ignoring Common Crypto for years and it has only gotten worse with Swift.zaph

1 Answers

3
votes

I've encountered this very problem myself. Here's how you resolve it:

  1. Create a module map file (here's my file).
  2. Copy the latest CommonCrypto.h header.
  3. Create a directory CommonCrypto for both these files.
  4. Copy the directory (via drag-and-drop) to your project.
  5. Add the directory path under SWIFT_INCLUDE_PATHS for your target framework.

This should allow you to use import CommonCrypto wherever you want (for Swift, not Objective-C).

Edit: Seems like I misread the question initially. You want to use CommonCrypto in Objective-C and then use that from Swift. Here's some advice: don't #import CommonCrypto in your public headers, but rather just internally. Wrap all your crypto-structures so that there's no public dependency for CommonCrypto whatsoever, and then just use it from Swift via the default bridging procedure.