且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在iOS应用程序项目中使用带有Swift代码的iOS Cocoa Static Library项目中的Objective-C代码

更新时间:2023-11-09 09:50:46

此过程似乎有效(对于单个应用程序目标):

This procedure seems to work (for single app target):


  1. 不要添加 import TestLibrary ,因为Swift和Objective-C代码都将驻留在同一个应用程序目标中

  2. 创建Test-Bridging-Header.h进行测试并添加# importTestLibrary / TestLibrary.h

  3. 设置构建设置 Objective-C Bridging Header:Test / Test-Bridging-Header.h for Test

  4. 从TestLibrary拖动libTestLibrary.a(在P下)使用二进制文件(在构建阶段)进入测试的链接库

  5. 添加 let test = TestLibrary()例如在ViewController.swift里面 viewDidLoad

  1. Do not add import TestLibrary, since both the Swift and Objective-C code will reside in the same app target
  2. Create Test-Bridging-Header.h to Test and add #import "TestLibrary/TestLibrary.h"
  3. Set build setting Objective-C Bridging Header: Test/Test-Bridging-Header.h for Test
  4. Drag libTestLibrary.a from TestLibrary (under Products) into Test's Link Library With Binaries (under Build Phases)
  5. Add let test = TestLibrary() e.g. inside viewDidLoadin ViewController.swift

Voila ......

Voila ...