How can i use the libraries after importing dependencies using cocoapods? - ios

I am facing issues in actually using the libraries contained within the dependancies. I followed the procedure up to the letter but yet xcode gives me errors when i try to import the kit i need to use. Heres what i have done:
create pod file at the project directory
install the pod file with dependancies
open .xcworkspace file created
create a bridging header in objective c
enter path of the bridging header to the build settings
After doing all of this, when i write the import statement (eg. import IMFData) xcode shows that it doesnt exist/ cant be found.
Could somebody shed some light on the what i am missing?

Try adding use_frameworks! to your pod file and then run pod install again. You won't need to use a bridging header then and will be able todo import IMFData alternatively if you aren't using Frameworks when you use the bridging header you don't need to use the import IMFData just access the classes within your swift class.

Related

Mixed language framework with Cocoapods

I'm creating Swift framework that will be distributed via Cocoapods. Inside MyFramework I use few frameworks installed via Cocoapods. Importing frameworks written in swift works fine, but I get trouble importing objc framework. I want to use CardIO inside MyFramework and add it as pods submodule, so user can optionally install it like pod 'MyFramework/CardIO'. After installing CardIO pod in MyFramework, I try to import it in MyFramework-umbrella-header like:
#import "CardIO/CardIO.h"
but get the error:
"Include of non-modular header inside framework module ".
I also check this answer, but this doesn’t work when importing objc framework. Any idea is it possible to import objc framework that installed via Cocoapods to Swift framework?
[FIXED]: The problem was in CardIO podspec, they import only .h files as source_files. So after including .m files to source files: .source_files = 'CardIO/*.{h,m}' Cocoapods generate CardIO modulemap, then it's possible to import CardIO module in Swift framework.

Install a Library without cocoapods

I am trying to install this library without using Pods. In their git, they explain that it's possible to do it by dragging the .xcodeproj file on the user project:
Yes you can copy it the classes like before. However it's more
comfortable to drag the xcodeproj to the project. It's not recommended
to drag the sources themselves, as this will make updating Chrats in
your project more difficult.
By dragging the project I get an error When I try to import the module:
No such module 'Charts'
I also selected my project -> Build Phases -> Link Binary With Libraries and added the Charts.framework. That didn't solved the problem.
I think to use any of the cocoa pods you have to build a header file as maybe the code that you are going to use might be in objective C and you might be using swift.
Simply create briding header file with named
"projectname-bridging-header.h" at root of your project.
Now got to build setting of project and in that do below changes:
Install objective-c compatibility header : YES
objective-C briding header : set path of your bridging header like
"projectname/briding header file name.h"
once its done import all your objective c file of pods which u want
use in swift app.
Note : if required then set the path as a recursive in the resource headers and Swift compiler search section.
let me know if any issues :)

Xcode/Swift: How to import a framework without actually including 'import xxx' in file

I've been following a Firebase tutorial for Swift here.
In the project I don't see any explicit 'import FirebaseXXX' within any of the files and was curious how this was being done.
I'm trying to get the same behavior in project but haven't had much luck yet. I have the same Bridging Header in my project, I've tried building/cleaning my project, and I've done 'pod update' and 'pod install' after adding the different pods to my Podfile.
So how exactly is this being done?
Thanks!
If you look at the bridging header (Grocr-Bridging-Header.h), they import the framework there
#import <Firebase/Firebase.h>
Objective-C #imports that happen in the bridging header are global across swift files in the project.
If you are using the swift framework, you'll need to import Firebase at the top of the files to use the framework.
Also see Cannot import Firebase in Swift app

CocoaPods not building target for Crittercism

I added pod 'CrittercismSDK' to my Podfile and ran pod install, it finished with no error, all good.
Using import Crittercism gives No such module error. I looked into the Pods/ directory, there source code is there; however, the Pods project doesn't have a target called Pods-MyProject-Crittercism (but it does have targets for each dependency).
Build keeps failing because the import isn't found. What am I doing wrong?
PS: I'm using use_frameworks! directive in my Podfile, and I have another obj-c library that works fine, so I don't know why this one isn't working.
While this is not a general answer, I have found that:
Not using #use_frameworks
Using a Bridging-Header.h containing #import "Crittercism.h"
Not importing CrittercismSDK in the Swift class, but merely executing Crittercism.enableWithAppID("appId") does the trick.
See if below steps helps in your case. What version of pod/Xcode in use? It will be great if you can share your pod file, thanks.
Install dependencies using Cocoapods and the use_frameworks! flag.
As you need to use a Objective-C dependency, create a Bridging header. You can create one easily by importing an Objective-C class to your Swift project, than remove it (the wizard should ask you if need a bridging header). Otherwise, create a new header file. Then, navigate to your target configuration and enter the name of your file in Swift Compiler - Code Generation > Objective-C Bridging header.
Still in your target configuration, add a new entry in Search Paths > User Header Search Paths: Pods as value and flag it as recursive.
Remove any import instruction from your code, relative to your Objective-C library.
Build your project. You should have a success.

Adding SocketRocket to a Swift project through Pods

I'm trying to add the SocketRocket framework to my Swift project using pods and I haven't been able to get the import to work on the Swift side.
I added the following entry to the Podfile:
pod 'SocketRocket', '0.2.0'
And ran pod install.
Then added the bridging header with:
#import <ScoketRocket/SRWebSocket.h>
In my ViewController, Xcode doesn't find the header file:
import SRWebSocket
fails. I really hope to get this done through pods instead of manually adding the files to the project.
Thanks.
Is there a typo ?
#import <ScoketRocket/SRWebSocket.h>
ScoketRocket/SRWebSocket.h
You have to import modules by their module name and not their header name:
import SocketRocket
If you use that in your view controller, then you wouldn't even need an import in the bridging header. Module Imports work with CocoaPods since >= 0.36 with frameworks support, which you have explicitly enable by putting the following in your Podfile:
use_frameworks!
You can still use SocketRocket with older versions of CocoaPods and without this directive from Swift, by adding the import statement to the bridging header like you already figured out. If you do that, you don't need a further import statement in your view controller. The bridging header makes imports available for the whole Swift module.

Resources