Using Objective-C code in iOS Cocoa Static Library project with Swift code in iOS Application project

99封情书 提交于 2019-12-04 17:00:17

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

  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 ...

In my case, I have to add all the .h file's of the Framework in the Bridging file, that fixed the issue. Also remove the import TestLibrary from the swift files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!