简体   繁体   English

Xcode swift 应用程序如何在 swift 静态库中调用函数?

[英]how can an Xcode swift app call functions in a swift static lib?

I have two xcode projects (1) a swift static lib, and (2) a swift app.我有两个 xcode 项目(1)一个 swift 静态库,和(2)一个 swift 应用程序。

What are the steps to have the swift app call a function in the swift lib?让 swift 应用程序调用 swift 库中的函数的步骤是什么?

  1. Create a new workspace: File > New Workspace or ^ + + N创建新工作区:文件 > 新建工作区或^ + + N
  2. Add both your .xcodeproj files to the workspace by drag and drop.通过拖放将两个.xcodeproj文件添加到工作区。
  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.在工作区中选择您的主项目,然后在常规选项卡下的框架、库和嵌入内容中,单击底部的 + 图标并将库的 .a 文件添加为依赖项。
  4. On the file of your project where you want to use a function from your library, import the module ( import YourStaticLib )在要使用库中函数的项目文件中,导入模块( 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.注意:确保您要使用的类/结构/函数在您的库中声明为public

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM