I try to integrate Swift
code in my app.My app is written in Objective-C
and I added a Swift
class. I\'ve done everything described he
Using Swift Classes in Objective-C
If you are going to import code within an App Target (Mixing Objective-C and Swift in one project) you should use the next import line #import "<#YourProjectName#>-Swift.h"
to expose Swift code to Objective-C code [Mixing Swift and Objective-C code in a project]
In this post I will describe how to import Swift static library to Objective-C code
Xcode version 10.2.1
Follow Create Swift static library with next additions:
Expose Swift API. To use Swift's functions from Objective-C[About]
After building you should find a
file that should be located into DerivedSources
[File not found]
Drag and drop
the binary into the Xcode project[About]
Link Library
[Undefined symbols] [Link vs Embed]
Project editor -> select a target -> General -> Linked Frameworks and Libraries -> add -> Add Others... -> point to `lib.a` file
//or
Project editor -> select a target -> Build Phases -> Link Binary With Libraries -> add -> Add Others... -> point to `lib.a` file
Add Library Search paths
[Library not found for] [Recursive path]
Project editor -> select a target -> Build Settings -> Search Paths -> Library Search paths -> add path to the parent of `lib.a` file
Add Header Search Paths
[Module not found] [Recursive path]
Project editor -> select a target -> Build Settings -> Search Paths -> Header Search Paths -> add path to generated `-Swift.h` file
Add empty .swift file
to the Objective-C project.[Undefined symbols] When Xcode ask press Create Bridging Header
(it will create module_name-Bridging-Header.h
) and setup a path to this file in
Project editor -> select a target -> Build Settings -> Swift Compiler - General -> Objective-C Bridging Header
Import module to the Objective-C client code[File not found] [module_name]
#import "module_name-Swift.h"
More examples here