I am building a framework that contains links to other frameworks, and the parent Framework is Obj-C. One of the child frameworks is Swift and I am getting errors 'module not found'.
How do I link a Swift framework to an Obj-C framework ? If this task was to simply add Swift source code to Obj-C source code, then I would know what to do...but it's not. Any help would be appreciated.
I think you need a bridging header. If I have this right, you have a framework written in Objective-C, but your Xcode project written in Swift. In that case, you have to create a bridging header and then use #import in the bridging header to access the code in Swift. You would then import the framework in the swift page/class that you want to implement code into. Here is a great video on YouTube on how to do it!
NOTE: In the video, there is a #ifndef, #define, and #endif ... which I don't believe you need in Xcode 7.
Related
I would like to use a Swift library in my Objective-C IOS app. I have the Swift library setup as a separate project, which builds fine in XCode. I can drag the generated Swift framework from the Swift project into the "Frameworks, Libraries and embedded content" list of my Objective-C project target. It appears with an "Embed & Sign" label.
The Apple description here: https://developer.apple.com/documentation/swift/importing-swift-into-objective-c states that
You can work with types declared in Swift from within the Objective-C
code in your project by importing an Xcode-generated header file. This
file is an Objective-C header that declares the Swift interfaces in
your target, and you can think of it as an umbrella header for your
Swift code. You don’t need to do anything special to create the
generated header—just import it to use its contents in your
Objective-C code.
When I look inside the swift .framework file, I can see the header file there. But when I import it in one of my Objective-c .m files, then the compiler says that the file is not found. I have tried both the
#import "Starscream-Swift.h"
and the
#import <Starscream/Starscream-Swift.h>
syntax.
How can I convince XCode to use the header file from the Swift framework? Do I need to copy that header somewhere, maybe? And what else do I need to think about to use a Swift library from an Objective-c IOS app?
I am using XCode version 13.4.1.
By the way, the Swift library I am trying to use is Starstream.
Xcode-generated header file is required when your own project has Objective-C and Swift classes mixed. When dealing with frameworks you either include the framework's umbrella header like this:
#import "SwiftFramework/SwiftFramework.h"
Or, more preferably, you import it with #import expression:
#import SwiftFramework;
Be advised, that only part that is exposed to Objective-C runtime is accessible from this framework (i.e. public/open classes inherited from NSObject or some other Cocoa classes)
I am trying to integrate this https://github.com/gareth-cross/kalman-ios project with my own Swift project in Xcode.
When building the project I receive 2 errors:
kalman-ios/matrix.hpp:28:10: error: 'cmath' file not found
failed to emit precompiled header
'/Users/.../Build/Intermediates.noindex/PrecompiledHeaders/Tron-iOS-Bridging-Header-
swift_J9ENU1M0P5CE-clang_M49XZJR5TLTE.pch'
for bridging header '/Users/.../Filter/Tron-iOS-Bridging-Header.h'
My project is purely Swift, and the kalman-ios project is a mixture of ObjC and ObjC++.
My bridging header file is:
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "KFEstimator.h"
For more context, the kalman-ios project is structured as:
KFEstimator.mm makes calls to AttitudeESKF.cpp makes calls to matrix.cpp
My initial thought was the cmath file error was the cause for the bridging header error. But I have almost no experience outside Swift and don't know how to go about fixing it. Up until yesterday, I wasn't even aware that you could use ObjCPP.
Any help is appreciated!
I have solved the issue. I was mistaken and believed that the repository was Objective-C making calls to Objective-C++.
It was actually all Objective-C++.
I was able to make direct calls to the Objective-C++ functions by following this video guide.
I've my own old framework which is only compatible in objective c, but Now I open in new xcode and added few swift classes (Xcode not gave me option to create bridging as this do in normal App when you add swift class in objective c project), Also Xcode gave me suggestion to update build setting and I updated those and currently I'm on Xcode 8.2.1. Now I try to build but I am getting few error as you can see in picture . I googled and found solution to delete derive data and quite xcode and open and clean. I done Everything but didn't workout.
Is bridging can be possible in framwork.
If not possible then how can I achieve.
Need help and suggestion.
When you are mixing Swift/Objc inside a framework, you can import Swift code for Objective-C use and import Objective-C from Swift.
First, ensure that Define Settings is set for the current framework target.
To import Swift into Objective-C:
In each Objective-C file that requires the Swift code, import the generated Swift header with the complete current Framework Path : #import <Framework/Framework-Swift.h>
To import Objective-C into Swift:
Ensure you have an umbrella header. The path can be found inside the Build Settings of the target. In this header, import all the needed Objective-C headers like normally in Objective-C: #import "Header"
Source: https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-ID122
I have created a dynamic framework with Swift language. In this framework I am using mailcore2-ios that was build by Objective-C code. So how can I use it in swift file of my framework?
I try "public" and add a header .h file to umbrella but it still not work, have so much error for other header file as the image what I attach.
Xcode does not allow the use of bridging headers in framework targets. You should use the methods described here : http://iosdeveloperzone.com/2014/10/03/using-commoncrypto-in-swift/
I must have started from scratch about 4 times already. I've followed the solutions listed below but I still have an issue (which I think has something to do with the bridging header file).
Note: I have tried manually creating the bridging header as well as the automated solution Xcode offers when you drag some Objective-C files into a Swift project.
Swift Bridging Header import issue
Connect Objective C framework to Swift iOS 8 app (Parse framework)
Here are the main errors I am seeing. I've tried moving the header file up a level/down a level and it still claims to not see it. Everything is currently where Xcode put it when I selected "Yes" when prompted to created the bridging header automatically. You can also see the full contents of my bridging header.
The "Cannot find protocol declaration for NSObject" error usually refers to circular references problems.
I'm wondering why you put all those standard Apple frameworks in the bridging header? This might be the problem. This special file is supposed to "bridge" Swift and Objective C worlds together, so if you've already referenced and linked your app against those frameworks in your Swift code, you shouldn't need to do it again in the bridging header.
Try to remove all Apple-provided frameworks from your bridging header and only leave the specific ones (IBM....h), and see if it works?
If it doesn't, then start with Foundation/Foundation.h only...