Cocoapods error while installing Swift library in Objective-C project - ios

I am working with objective-C, i wanted to implement a Charts in it which is in Swift. While installing pod i got this error:
"Pods written in Swift can only be integrated as frameworks; add use_frameworks! to your Podfile or target to opt into using it. The Swift Pod being used is: Charts"
How can i use this Library in my project ?

You cannot use Swift pods directly in the project using pods written in Swift and Objective-C. Swift pods can only be created as frameworks. Objective-C pods can be created as frameworks and with source code files directly as well. There is a catch when you include use_frameworks!, all the pods have to be frameworks. So you need to check if the Objective-C pods that you have included have framework pods.

Related

Embedding pods to static library iOS

I'm creating a static library in iOS using Objective-C. This library will gather data from the app where this library is integrated, the gathered data from the app will be sent to the server.
I'm just wondering if is it possible to embed a cocoa pods framework in my library like AFNetworking?
Thanks in advance
Yes. It seems to be possible.
I created a static library project and tried to integrate cocoapods in to it with below steps.
pod init
Then edited the podfile to integrate AFNetworking pod in the project like below
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target 'Testing' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
pod 'AFNetworking', '~> 3.0'
# Pods for Testing
end
then gave
pod install
I get the below warning
[!] The Podfile contains framework or static library targets
(Testing), for which the Podfile does not contain host targets
(targets which embed the framework). If this project is for doing
framework development, you can ignore this message. Otherwise, add a
target to the Podfile that embeds these frameworks to make this
message go away (e.g. a test target).
As the first line in the warning says we are doing framework development, hence we can ignore this message and it should work fine.
Also my suggestion is to use Alamofire instead of AFNetworking as Alamofire is swift based and AFNetworking is objective-c based.

How to integrate both Objective-C and Swift pods in same project in iOS app

I am doing Objective-C in iOS app. But the problem is I want to add few Objective-C apis into that I added successfully earlier with cocoa pods, But, now I want to add Swift Api through cocoa pods, but the problem getting while installing is following.
[!] Pods written in Swift can only be integrated as frameworks; add use_frameworks! to your Podfile or target to opt into using it. The Swift Pods being used are: apis
But I can't add this manually due to its large api and it contains sub folders.
But, if I remove "#" key from use_frameworks!, its getting installed, but, the old Objective-C apis getting file not found in my project.
Even I have very basic knowledge at installing frameworks/apis through cocoa pods.
Can any one suggest me how to over come this.
use_frameworks! will work with Objective-C pod only if they are dynamic frameworks not static libraries. Most of the popular third party libraries are using dynamic frameworks like AFNetworking, GoogleMaps etc.
Make sure all your Objective-C pods are dynamic frameworks. If you are not sure just create a sample project with cocoapods and use use_frameworks!. Try adding one by one, all the pods and find out which one is the culprit.
I had that problem once, what I did was use use_frameworks! like you mentioned, and then I changed how the Objective-C imports are written.
The command use_frameworks! turns each pod into a Framework, so in your projects the .h and .m files are no longer visible to the import like they would usually.
As a result, instead of using for example #import <AFNetworking/AFNetworking.h>, you do #import AFNetworking;
From my own experience, and maybe it was just a special case for my project. But turning everything into frameworks slowed down the compile time on Xcode and it made my App Package bigger for some reason.
Podfile file:
platform :ios, '10.0'
use_frameworks!
def pods
pod 'Alamofire', '= 4.4'
pod 'SwiftyJSON' '= 3.1.4'
pod 'MBProgressHUD'
end
target 'YourProject' do
pods
end
YourProject-Bridging-Header.h
#import <MBProgressHUD/MBProgressHUD.h>
Build Settings

Swift Framework Added via Cocoapods into Objective-C App - "Module not found"

In Xcode 8 I'm having trouble importing any Swift 2.3 or 3 framework that was added with Cocoapods into my project.
There is a public umbrella.h file, but for some reason Xcode can't find the framework when I try to #import it.
As an example, create any Objective-C project, use the following Podfile, pod install, and then try the #import. It asks me to update the code to swift 2.3 or 3 even if that code is already Swift 2.3 or Swift 3 code. I've cleaned and tried to rebuild as well.
platform :ios, '8.0'
use_frameworks!
target 'testingFrameworks' do
pod 'SwiftyJSON'
end
Did I miss a step?
I used socketIO and was having the same problem. My solution to this is:
Close project.
Delete pod files, delivered files, pod framework, workspace file (clean up project)
pod install
Reopen workspace, upgrade swift syntax if xcode ask for, build a few times.
You might need to fix something for the new swift.

Include CocoasMQTT library in swift framework project

I am pretty new to swift and iOS development. I am trying to write a framework using swift 2.0. I need to import the CocoasMQTT library in my framework. I am using cocoa pods approach for this and i added
use_frameworks!
pod 'CocoaMQTT'
in my pod file. After this I pod install. Now in my Pods directory I can only see debug.xconfig and release.xconfig files(in xcode directory view). I think this should have worked but I am unable to import the library in my swift classes as it says that "No Such module 'CocoaMQTT'" when i try
import CocoaMQTT
in my code.
Can anyone explain if I am doing something wrong. P.S., as I have included use_frameworks! and I am using iOS version 9 for development so I think I don't have to write the Objective C bridge header.
I had same problem to. My problem cause about using CocoaPods. I think you open .xcodeproj file by Xcode but if you install pods you must open .xcworkspacefile. You should look raywenderlich's forum for using cocoapods.
https://www.raywenderlich.com/97014/use-cocoapods-with-swift
Close your xcode after pod install, and open the .xcworkspace file generated by Cocoapods.

Using cocoapods without use_frameworks! in Swift

According to this tutorial, we should add use_frameworks! to Podfile in Swift project. But how to use third-party code in .m in the same project?
One possible way is,
Do NOT add use_frameworks! to Podfile
Import header in ...-Bridging-Header.h
Then, I can use third-party code in both .swift and .m file
But when I try to import header in ...-Bridging-Header.h, it just throw *.h file not found error, how to fix this issue?
Past
Up to CocoaPods 1.4.x (included), it was NOT possible to use CocoaPods with Swift code without use_frameworks!.
Present: 1.x.x and above
Nowadays, with CocoaPods 1.x.x (I verified it with 1.4.0), it's common to use use_frameworks! for both Swift and ObjC projects: it allows for a mix of the two languages in any way you want without issues:
You'll be able to use a Swift dependency in an Objective-C project.
You'll be able to use an Objective-C dependency in a Swift project.
Present: 1.5.x and above
Nowadays, CocoaPods 1.5.0 supports integrating swift pods as static libraries. Try it (sudo gem install cocoapods) and enjoy removing use_frameworks! from your Podfile.
Note that for iOS:
Apple requires Xcode 10.1 minimum, which is only well supported starting CocoaPods 1.6.0, so don't bother using older versions of CocoaPods.
Apple will require Xcode 11 minimum in April 2020, for which I would only use CocoaPods 1.7.5 or newer, together with xcodeproj 1.13.0 or newer.

Resources