Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't import CommonCrypto in mixed language framework

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

like image 284
Yakir Yehuda Avatar asked Oct 19 '22 09:10

Yakir Yehuda


1 Answers

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.

like image 174
Vatsal Manot Avatar answered Oct 21 '22 06:10

Vatsal Manot