How to get CommonCrypto working with your own Xcode 8 / Swift 3.0 framework
- Prepare “CommonCrypto” folder containing modulemap files, CommonCrypto.xcconfig and Info.plist. You can grab it from here or create your own.
- Create a new Xcode project (cross-platform).
- Add targets for each platform you need.
- Under project settings Info tab set configuration for each target to CommonCrypto.xcconfig (for both Debug and Release).
- Under General tab for each target, you might want to check “Allow app extension API only” which will make sure that you can use the framework even in app extensions safely.
- Delete not needed folders in the project such as “CommonCrypto-iOS”, “CommonCrypto-watchOS”, “CommonCrypto-macOS” and “CommonCrypto-tvOS”. Also delete those folders from your filesystem under project directory. Everything you need is just “CommonCrypto” folder containing Info.plist, CommonCrypto.xcconfig and modulemap files.
- For each target, under Build settings search for “Product name” and replace what you see there with “CommonCrypto” (instead of “CommonCrypto-watchOS”, for example).
- For each target, under Build settings search for “Product Bundle identifier” and replace it to have the same bundle id for all targets. In my case, I replace org.world.CommonCrypto-watchOS (and so on) with org.world.CommonCrypto.
- For each target, under Build settings search for “Info.plist File” (for watchOS target you’ll have something like “CommonCrypto-watchOS/Info.plist” there), so replace it with “CommonCrypto/Info.plist”.
- Now, there are two possible ways to use it:
a) Add this CommonCrypto project as subproject into your parent swift framework;
b) Build binary for each target which produces CommonCrypto.framework for each platform, then copy those *.framework files with their parent folders into your parent project via dropping them to Xcode and applying “Copy items if needed” checkbox (unselect any target membership though). If you drop them without folders Xcode will not allow to do that because their names are equivalent.
Now, just use import CommonCrypto statement in your target swift classes, the underlying CommonCrypto C API is available now.
Note: no other settings in Xcode were adjusted, only the ones listed above.