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.
Related
I was trying to make a demo project which uses a POD dependency of this URL PageMenu POD install correctly but gives me many errors on building this dummy app as many methods' are renamed in latest iOS SDK and swift 4.2. I have solved this problem before on my office project but can't remember right now. Any help will be appreciable. I am attaching a screenshot with this project.
Reasons for the problem: Swift version of my project is 4.2 and I am using a library which was built in swift version 4. So some of the method's name in latest iOS SDK is renamed from Swift 4.
Solution: I need to set Swift version 4 for that pod dependency and recompile this project.
Note: Any third party pod that doesn't support the latest swift must be compiled with the supported version of swift for pod dependency
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.
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.
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.
I've been using use_frameworks! directive so that I can use some dependencies on my project. If I comment that directive, I get a red message saying
Pods written in Swift can only be integrated as frameworks; this feature is beta. Add 'use_frameworks!' to your Podfile or target to opt into using it.
Today I decided to use Google Analytics for iOS but when running $pod install I get
The 'Pods-MyProject' target has transitive dependencies that include static binaries
Googling around I found out it is caused because of the use_frameworks! directive and I should remove it. So I'm between a wall and a sword, what can I do to be able to work with these libraries?
PS: We are required to manage dependencies using Cocoapods, so including it in a different way is not an option. Also, I don't have a bridging header in my project, but I'm still able to work with libraries using import MyDependency