Skip to content

Instantly share code, notes, and snippets.

@yamaya
Last active January 10, 2020 01:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save yamaya/6245b211dfa1ca40c82d to your computer and use it in GitHub Desktop.
Save yamaya/6245b211dfa1ca40c82d to your computer and use it in GitHub Desktop.
Swift製のframeworkでlibcommonCrypto.dylibを使う方法

ios - Importing CommonCrypto in a Swift framework - Stack Overflow より

背景

  • Appleが解説しているのはObjective-Cなframeworkを使用するケース
  • CommonCryptoはPure Cなdylibなので同じ方法では不可能

方法

CommonCrypto.frameworkを自分で作る。

  1. あなたのframeworkプロジェクト内にCocoa Touch Frameworkプロジェクトを作成する

  2. プロジェクトの名前を CommonCrypto にする

  3. 自動生成されるUmbrellaヘッダは削除して良い

  4. modulemapファイルを作る

    1. iphneos.modulemap
    module CommonCrypto [system] {
        header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/CommonCrypto.h"
        export *
    }
    
    1. iphonesimulator.modulemap
    module CommonCrypto [system] {
        header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/CommonCrypto/CommonCrypto.h"
        export *
    }
    
    1. macosx.modulemap
    module CommonCrypto [system] {
        header "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/CommonCrypto/CommonCrypto.h"
        export *
    }
    
  5. xcconfigファイルを作成する

    MODULEMAP_FILE[sdk=iphoneos*]        = $(SRCROOT)/CommonCrypto/iphoneos.modulemap
    MODULEMAP_FILE[sdk=iphonesimulator*] = $(SRCROOT)/CommonCrypto/iphonesimulator.modulemap
    MODULEMAP_FILE[sdk=macosx*]          = $(SRCROOT)/CommonCrypto/macosx.modulemap
    
  6. xcconfigをDebug/Release両Configurationに設定する (Project > Info > Configurations)

  7. あなたのframeworkプロジェクトのBuild Phases > Target DependenciesにCommonCrypto.frameworkを追加する

  8. あなたのframeworkプロジェクトのソースで import CommonCrypto とすれば CommonCrypotの関数が使える

以上で、ビルドは通る。

補記

審査に注意? > Nested sqlite3 framework causing app store rejection · Issue #88 · stephencelis/SQLite.swift

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment