Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

importing-commoncrypto-in-a-swift-framework

...

You can

...

actually

...

build

...

a

...

solution

...

that

...

"just

...

works"

...

(no

...

need

...

to

...

copy

...

module.modulemap

...

 and SWIFT_INCLUDE_PATHS

...

 settings over

...

to

...

your

...

project,

...

as

...

required

...

by

...

other

...

solutions

...

here),

...

but

...

it

...

does

...

require

...

you

...

to

...

create

...

a

...

dummy

...

framework/module

...

that

...

you'll

...

import

...

into

...

your

...

framework

...

proper.

...

We

...

can

...

also

...

ensure

...

it

...

works

...

regardless

...

of

...

platform

...

(iphoneos,

...

 iphonesimulator,

...

or macosx).

...

  1. Add

...

  1. a

...

  1. new

...

  1. framework

...

  1. target

...

  1. to

...

  1. your

...

  1. project

...

  1. and

...

  1. name

...

  1. it

...

  1. after

...

  1. the

...

  1. system

...

  1. library,

...

  1.  e.g.,

...

  1. "CommonCrypto".

...

  1. (You

...

  1. can

...

  1. delete

...

  1. the

...

  1. umbrella

...

  1. header,

...

  1.  CommonCrypto.h.)

...

  1. Add

...

  1. a

...

  1. new Configuration

...

  1. Settings

...

  1. File

...

  1.  and name

...

  1. it,

...

  1.  e.g.,

...

  1. "CommonCrypto.xcconfig".

...

  1. (Don't

...

  1. check

...

  1. any

...

  1. of

...

  1. your

...

  1. targets

...

  1. for

...

  1. inclusion.)

...

  1. Populate

...

  1. it

...

  1. with

...

  1. the

...

  1. following:

...

  1. MODULEMAP_FILE[sdk=iphoneos*]

...

  1.  = \

...

  1.  $(SRCROOT)/CommonCrypto/iphoneos.modulemap MODULEMAP_FILE[sdk=iphonesimulator*]

...

  1.  = \

...

  1.  

...

  1. $(SRCROOT)/CommonCrypto/iphonesimulator.modulemap MODULEMAP_FILE[sdk=macosx*]

...

  1.  = \

...

  1.  

...

  1. $(SRCROOT)/CommonCrypto/macosx.modulemap

...

  1. Create

...

  1. the

...

  1. three

...

  1. referenced

...

  1. module

...

  1. map

...

  1. files,

...

  1. above,

...

  1. and

...

  1. populate

...

  1. them

...

  1. with

...

  1. the

...

  1. following:

...

    • iphoneos.modulemap

...

    • module

...

    •  CommonCrypto

...

    •  [system]

...

    •  {

...

    •  

...

    • header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/CommonCrypto.h"

...

    •  export * }
    • iphonesimulator.modulemap

...

    • module

...

    •  CommonCrypto

...

    •  [system]

...

    •  {

...

    •  header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/CommonCrypto/CommonCrypto.h"

...

    •  export * }
    • macosx.modulemap

...

    • module

...

    •  CommonCrypto

...

    •  [system]

...

    •  {

...

    •  

...

    • header "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/CommonCrypto/CommonCrypto.h"

...

    •  export * }

    (Replace "Xcode.app"

...

  1. with

...

  1. "Xcode-beta.app"

...

  1. if

...

  1. you're

...

  1. running

...

  1. a

...

  1. beta

...

  1. version.

...

  1. Replace 10.

...

  1. 11with your

...

  1. current

...

  1. OS

...

  1. SDK

...

  1. if

...

  1. not

...

  1. running

...

  1. El

...

  1. Capitan.)

...

  1. On the Info tab of your project settings, under Configurations, set the Debug and Releaseconfigurations of CommonCrypto to CommonCrypto (referencingCommonCrypto.xcconfig).

  2. On your framework target's Build Phases tab, add the CommonCrypto framework to Target Dependencies. Additionally add libcommonCrypto.dylib to the Link Binary With Librariesbuild phase.

  3. Select CommonCrypto.framework in Products and make sure its Target Membership for your wrapper is set to Optional.

You should now be able to build, run and import CommonCrypto in your wrapper framework.

For an example, see how SQLite.swift uses a dummy sqlite3.framework.