Home > Back-end >  how can an Xcode swift app call functions in a swift static lib?
how can an Xcode swift app call functions in a swift static lib?

Time:11-11

I have two xcode projects (1) a swift static lib, and (2) a swift app.

What are the steps to have the swift app call a function in the swift lib?

CodePudding user response:

  1. Create a new workspace: File > New Workspace or ^ N
  2. Add both your .xcodeproj files to the workspace by drag and drop.
  3. Select your main project in the workspace, and under the General tab, in Frameworks, Libraries and Embedded Content, click the icon at the bottom and add your library's .a file as a dependency.
  4. On the file of your project where you want to use a function from your library, import the module (import YourStaticLib)
  5. Use your library functions :)

Note: Make sure the classes/structs/funcs you want to use are declared as public in your library.

  • Related