Swift’s compatibility with C and Objective-C lets you create a project that contains files written in either language.
Questions tagged [objective-c-swift-bridge]
117 questions
128
votes
19 answers
Swift Bridging Header import issue
Following instructions, I've created a bridging header and added to my project. Unfortunately, the following error occurred:
:0: error: could not import Objective-C header '---path--to---header/....h'
In build settings I added header search path…

Nikita Semenov
- 2,111
- 4
- 18
- 31
69
votes
4 answers
Cannot access property on Swift type from Objective-C
I am trying to access a Swift class's Double? property from Objective-C.
class BusinessDetailViewController: UIViewController {
var lat : Double?
var lon : Double?
// Other elements...
}
In another view controller, I am trying to…

tranvutuan
- 6,089
- 8
- 47
- 83
65
votes
25 answers
Failed to emit precompiled header for bridging header
I downloaded a project from GitHub, then pod the following files, some of which are written by OBJ-C and I used a bridge header.
pod ‘SnapKit’
pod ‘MJRefresh’
pod ‘Alamofire’
pod ‘Kingfisher’
pod ‘MBProgressHUD’
pod ‘pop’
pod ‘EVReflection’
pod…

Ringo
- 1,173
- 1
- 12
- 25
43
votes
4 answers
How do I remove a bridge header without getting errors?
I added a bridge header to my app the other day because I was trying to add Objective-C files to my Swift project. I was having trouble getting the connection to work(and I also did not know how to implement the Objective-C files), so I decided I…

Caleb Kleveter
- 11,170
- 8
- 62
- 92
27
votes
4 answers
How to modify SWIFT_MODULE_NAME?
The title says it all. I've searched in the build settings for SWIFT_MODULE_NAME, and nothing came up. I've also searched online, and there are references to this name, but there is no information on how it is defined. Furthermore, I couldn't find…

Sheamus
- 6,506
- 3
- 35
- 61
25
votes
1 answer
Type "SwiftClass" cannot conform to protocol "ObjcProtocol" because it has requirements that cannot be satisfied
I have an Objective-C protocol which I'm trying to implement in a Swift class. For example:
@class AnObjcClass;
@protocol ObjcProtocol
- (void)somethingWithAnArgument:(AnObjcClass *)arg;
@end
When I try to conform to it in a Swift…

Jesse Rusak
- 56,530
- 12
- 101
- 102
22
votes
3 answers
How do I convert NSDictionary to Dictionary?
I have already updated to XCode 8 and now I need to convert my code from Swift 2 to Swift 3.
Before, when I want to convert NSDictionary to Dictionary, I just wrote the following:
let post_paramsValue = post_params as?…

david
- 3,310
- 7
- 36
- 59
8
votes
1 answer
Objective-C - Swift bridging performance for existent codebase
A performance question for developers who have experience with adding swift into existent Objective-C codebase.
My premise is: eventually Bridging-Header.h might become really big (it might end up containing all 1.5k existent Objective-C classes…

Sash Zats
- 5,376
- 2
- 28
- 42
7
votes
0 answers
Forward declare a Swift class to use it in an Objective-C header
I'm trying to import a Swift class into an Objective-C header file. I know that Project-Swift.h bridge can only be imported into implementation files (.m) but I've got an Objective-C header that needs to declare a property that's defined in Swift.
I…

Shlomi Nissan
- 113
- 1
- 4
6
votes
1 answer
ProjectName-Swift.h Not Found / Generated Xcode 10
Running my project in Xcode 10 throws me this error
fatal error: 'Stories-Swift.h' file not found
I've tried multiple things including:
Adding a new swift file to the project and rebuilding it
Setting Defines Modules to Yes
Double checking my…

Giridhar
- 104
- 1
- 6
6
votes
1 answer
How to bridge Objective-C initWithError: method into Swift
I have a class defined in Objective-C, whose initializer is -initWithError: (the initializer can fail due to a dependence on an outside resource). I want this to bridge into Swift as init() throws. The regular initializer inherited from NSObject,…

Andrew Madsen
- 21,309
- 5
- 56
- 97
5
votes
2 answers
How to use Swift in React Native Turbo Modules
I followed the guide here to create a turbo module. This was fine.
https://reactnative.dev/docs/the-new-architecture/pillars-turbomodules
I want to use Swift code in this turbo module. I tried adding a Swift file with this code and modifying the…

Berry Blue
- 15,330
- 18
- 62
- 113
5
votes
2 answers
Accessing Swift protocol property implemented in an Obj-C class from another Swift class
I've seen lots of questions regarding implementing Obj-C protocols in Swift, but not so much the other way around, and I haven't seen this specifically.
I am using a mixed Obj-C / Swift codebase. I have a Swift protocol defined as…

Jordan
- 4,133
- 1
- 27
- 43
5
votes
2 answers
Call Swift func from Objective-C with parameter
I want to integrate a Swift class into an UIViewController class.
I think I made all settings correct. I have a class rURLTask:NSObject with a function:
@objc public func primer() {
print("primer")
}
In my .swift file and can call it from my…

heimi
- 499
- 7
- 16
5
votes
2 answers
Correct way to catch NSInvalidArgumentException when using NSExpression
I want to validate user created expressions (like "2+2", "5+7" or more complex). I use NSExpression class to parse and calculate this expressions. This is my Playground code:
import UIKit
let string = "2+2"
var ex:NSExpression?
do {
ex =…

Stanislav Chernischuk
- 975
- 1
- 11
- 24