Cecilia Humlelu
4 min readMar 28, 2019

--

Using C, C++ and Objective-C frameworks in Swift apps

I did a talk in try!Swift Tokyo this year about using C, C++ and Objective-C frameworks in Swift apps. The presentation was quite concise, so I decided to write down the content in details to provide more information.

The structure of this article will be divided into:

  • Language connections among C, C++, Objective-C and Swift
  • How to set up dependencies
  • Why wrappers and how to write wrappers

Language connections among C, C++, Objective-C and Swift

Photo credit: Cecilia Humlelu

C to Swift

C is 47 years old, and Swift is a new powerful open source language that has support for C. Even though it can not compile C code it has direct interoperability with C, so we can use compiled C code directly in Swift.

C++ to Swift

C++ and Swift can not talk directly and it needs some manual middle stage, for example C or Objective-C.

C++ is a superset of C and it provides the support of object oriented programming. Since Swift supports C one approach is to expose the C++ library with a C only API, and Swift apps can then use the library directly.

Objective-C++ can compile source files that contain a combination of C++ and…

--

--