Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Using C in Swift

codelynx
September 23, 2016

Using C in Swift

While programming in Swift, sometime it is necessary to deal with C libraries. This presentation will give you quick overview of how to use C library from your swift apps, and/or swift frameworks. [swift3]

codelynx

September 23, 2016
Tweet

More Decks by codelynx

Other Decks in Programming

Transcript

  1. Kaz Yoshikawa • Electricwoods LLC ୅ද / Digital Lynx Systems

    Inc. ෭୅ද • e-mail: [email protected] • twitter: @codelynx1 • Working History • Adobe Systems (Tokyo) • Lionbridge (Tokyo) • Quark (Tokyo / Denver) • Hummingbird Communications (Mt. View, USA) • Fact International (Vancouver, Canada) • Perle Systems (Toronto, Canada), etc.
  2. Using C in Swift • SQLite • OpenSSL • zlib

    • libxml2 • mysqllib • libetpan • commonCrypto
  3. What is module map? Module maps
 
 Module maps are

    specified as separate files (each named module.modulemap) alongside the headers they describe, which allows them to be added to existing software libraries without having to change the library headers themselves. http://clang.llvm.org/docs/Modules.html#module-maps
  4. Now you can use C identifiers in swift code JNQPSU6*,JU

    JNQPSUTRMJUF QVCMJDDMBTT5FTU4RMJUF@J04/40CKFDU\  QVCMJDDMBTTGVODUFTU \  MFUGJMFQBUI /45FNQPSBSZ%JSFDUPSZ BT/44USJOH BQQFOEJOH1BUI$PNQPOFOU UFTUTRMJUF   WBSEC0QBRVF1PJOUFS OJM  MFUTUBUVTTRMJUF@PQFO@W GJMFQBUI EC 42-*5&@01&/@3&"%83*5&]42-*5&@01&/@$3&"5& OJM   TXJUDITUBUVT\  DBTF42-*5&@0,   QSJOU TRMJUFPQFO    MFUTUBUVTTRMJUF@DMPTF EC    TXJUDITUBUVT\   DBTF42-*5&@0,    QSJOU TRMJUFDMPTFE    EFGBVMU    QSJOU TRMJUFFSSPS= TUBUVT     ^  EFGBVMU   QSJOU TRMJUFFSSPS= TUBUVT    ^  ^ ^ make sure it's public
  5. Attributes NPEVMFTRMJUF<TZTUFN>\ IFBEFSTRMJUFI FYQPSU  ^ The system attribute specifies

    that the module is a system module. When a system module is rebuilt, all of the module’s headers will be considered system headers, which suppresses warnings. This is equivalent to placing #pragma GCC system_header in each of the module’s headers.
  6. export NPEVMFTRMJUF<TZTUFN>\ IFBEFSTRMJUFI FYQPSU  ^ Export declaration¶ An export-declaration

    specifies which imported modules will automatically be re-exported as part of a given module’s API.
 
 The export-declaration names a module or a set of modules that will be re-exported to any translation unit that imports the enclosing module. Each imported module that matches the wildcard-module-id up to, but not including, the first * will be re-exported.
  7. Wrap Up • There are so many good libraries out

    there! • Use Bridging Header, if you like to use C library in your app • Use module, if you like to use C library in your framework