How to use CommonCrypto in iOS
Issue #480
Use modulemap
modulemap approach
I use modulemap
in my wrapper around CommonCrypto https://github.com/onmyway133/arcane, https://github.com/onmyway133/Reindeer
For those getting header not found
, please take a look https://github.com/onmyway133/Arcane/issues/4 or run xcode-select --install
- Make a folder
CCommonCrypto
containingmodule.modulemap
module CCommonCrypto {
header "/usr/include/CommonCrypto/CommonCrypto.h"
export *
}
- Go to Built Settings -> Import Paths
${SRCROOT}/Sources/CCommonCrypto
Cocoapods with modulemap approach
Here is the podspec https://github.com/onmyway133/Arcane/blob/master/Arcane.podspec
s.source_files = 'Sources/**/*.swift' s.xcconfig = { 'SWIFT_INCLUDE_PATHS' => '$(PODS_ROOT)/CommonCryptoSwift/Sources/CCommonCrypto' } s.preserve_paths = 'Sources/CCommonCrypto/module.modulemap'
Using
module_map
does not work, see https://github.com/CocoaPods/CocoaPods/issues/5271Using Local Development Pod with
path
does not work, see https://github.com/CocoaPods/CocoaPods/issues/809That’s why you see that my Example Podfile https://github.com/onmyway133/CommonCrypto.swift/blob/master/Example/CommonCryptoSwiftDemo/Podfile points to the git repo
target 'CommonCryptoSwiftDemo' do pod 'CommonCryptoSwift', :git => 'https://github.com/onmyway133/CommonCrypto.swift' end
public header approach
Ji is a wrapper around libxml2, and it uses public header approach
It has a header file https://github.com/honghaoz/Ji/blob/master/Source/Ji.h with
Target Membership
set toPublic
It has a list of header files for libxml2 https://github.com/honghaoz/Ji/tree/master/Source/Ji-libxml
It has Build Settings -> Header Search Paths
$(SDKROOT)/usr/include/libxml2
It has Build Settings -> Other Linker Flags
-lxml2
Cocoapods with public header approach
- Take a look at the podspec https://github.com/honghaoz/Ji/blob/master/Ji.podspec
1 | s.libraries = "xml2" |
🐝 Interesting related posts
- https://stackoverflow.com/questions/24004732/how-to-call-c-from-swift
- https://spin.atomicobject.com/2015/02/23/c-libraries-swift/
CommonCrypto from Xcode 10
From Xcode 10, we can just
1 | import CommonCrypto |