2

I am working with swift 3.2. I have made a bridging header file which has the following:

#import <CommonCrypto/CommonCrypto.h>

In my projects build setting I am pointing to my bridging header file but i am still getting the error 'No such module CommonCrypto' in my classes where I am using import CommonCrypto

update: header file:

#ifndef ProjectName_Bridging_Header_h
#define ProjectName_Bridging_Header_h

#import <CommonCrypto/CommonCrypto.h>

#endif
user2363025
  • 6,365
  • 19
  • 48
  • 89
  • can you show your entire bridging header, I imported common crypto the exact same way you did and mine is working fine – TNguyen Oct 23 '17 at 16:45
  • Have you tried [this](http://iosdeveloperzone.com/2014/10/03/using-commoncrypto-in-swift/)? – Daniel Oct 23 '17 at 17:00
  • 3
    you don't need to do `import CommonCrypto` if you already have it in your header file. You can just use it straight – TNguyen Oct 23 '17 at 17:08
  • @TNguyen if I remove import CommonCrypto then I get warnings saying 'use of unresolved identifier CommonCrypto' – user2363025 Oct 24 '17 at 08:29
  • Previoulsy I had commonCrypto in a framework and had used an aggregate. With that I needed to import CommonCrypto and use it like CommonCrypto.kCCOptionPKCS7Padding for example. I removed all my 'CommonCrypto.' references from my swift file and it worked- thanks for the help! – user2363025 Oct 24 '17 at 09:33

1 Answers1

2

I've found the workaround to make Xcode be able to find CommonCrypto via Swift module as stated here by Mihael Isaev.

I used such approach in my project (Xcode 9.3, Swift 4). I summarize steps as follows.

  1. Create a new directory namely CommonCrypto at the root of your project (or for me I created it at the same level of AppDelegate.swift file)
  2. Create a file name module.map inside that directory (done outside Xcode) with following content

    module CommonCrypto [system] {
       header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/CommonCrypto.h"
       export *
    }
    

    If you install Xcode elsewhere, you can manually find location of such .app yourself then append it with /Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/CommonCrypto.h or you can execute xcode-select -p to get the path of Xcode then append it with /SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/CommonCrypto.h

  3. Go to Build Settings in Xcode then search for swift compiler - search paths.

  4. Enter $(PROJECT_DIR)/<project name>/CommonCrypto into its Import Paths in which <project name> is your project name.
  5. Now you will be able to build the project, and Xcode would find such module.

Note: No need to add such CommonCrypto directory which hosts module.map file into Xcode via Add Files to .... It only used in compilation step thus no problem there.

haxpor
  • 2,431
  • 3
  • 27
  • 46
  • are you using rave framework ? inside commoncrypto module what has to be the path in my case `.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/CommonCrypto.h` where the commoncrypto is should i replace this ? – Midhun Narayan Dec 11 '18 at 10:47