Why I can't just use class from Pod of CocoaPods - ios

I have installed Pod to use iOS Charts but stuck at the first line of code!
tried build and clean project - nothing
Tried to link binary with libraries with Charts-framework and then import Charts but there is warning that my project is inside of Charts module so import is ignored.
Can't understand why this class (or other classes from this pod) is not visible for main project?

According to the lib, the pod has been written in swift so make sure your pod file has use_frameworks! command in it.
Also currently the project name and the pod name are same that is Charts.
This can lead to path issues. please solve that by changing name of the project.
It will work

Related

Using a CocoaPod dependency while developing a CocoaPod

I'm creating a CocoaPod, say MyPod, which depends on another Cocoapod, say RxSwift.
So I have this in MyPod.podspec:
s.dependency "RxSwift", "~> 3.0.1"
However, while developing MyPod, how can I actually use the dependency?
import RxSwift
// ^
// No such module 'RxSwift'
public class MyClass { //...
Is there a step I'm missing, or some common convention? It looks like some other projects like Moya are using Carthage to build dependencies while developing. Should I be doing that, or maybe adding a Podfile?
I know that this shouldn't be a problem for an Example App located within the repo, which would have its own Podfile. However, I'd like to still have tests located at top level, outside of the Example App, and to be able to actually build the framework while working on it, again, outside of an Example App.
I can't speak to whether or not to use CocoaPods or Carthage. Both have their strong points and weak points. Plus the decision should be made considering many factors, some of which you might not be able to control (like a client that insists you use CocoaPods!) So I'll skip that part.
However, to your question, indeed a pod you are developing can depend on another pod. You already have the correct s.dependency line. That's necessary.
However, I suspect that the reason why you were not able to reference the dependent pod could be because you did not have a Podfile in your 'tester/example' project and/or you did not do a pod install after adding the dependency in your Podspec.
The reason for this is requirement I suspect is that since the Podspec is not actually processed at all by Xcode, you're not actually downloading (or compiling) the dependency.
Instead, when you do the pod install (via command line of course), CocoaPods will create a Pods project with your development pod, the pods you depend on (in Podspec) as well as any other pods in your Podfile.
To test this theory, I:
Created a new pod (using CocoaPod's own 'pod lib create' (https://guides.cocoapods.org/making/using-pod-lib-create.html).
Opened the workspace that CocoaPod created for me and edited the Podspec to add the dependency s.dependency 'RxSwift', '~> 3.0.1'.
Added another pod in my Example App's Podfile (to demonstrate the difference between Podfile dependencies and Podspec dependencies.)
Performed pod install in the Example App's folder.
Edited my Pod's class to do something useful AND to add the import RxSwift line.
Added a label to my Example App ("Hello World" of course).
Used PureLayout to do all the auto layout constraints for the label (and to demonstrate how the Example project has access to both pods - the development pod as well as the referenced pod PureLayout.)
You can check out the demo I created on my public GitHub:
https://github.com/ericwastaken/CocoaPod-Dependency-Demo
Honestly, I've created several pods using the pod lib create and it does indeed create a nice structure that has always worked for me. For this reason, I would recommend always using it to create your pod's skeleton.
Xcode 8 comment: pod lib create still seems to create a Swift 1.x project. So, right after you use this tool, when you open Xcode, you'll be offered to "convert" to a newer version of Swift. I would let that conversion happen right then and there (the first time) so that you can be in Swift 2.x or 3.x syntax (you choose).
I ended up using Carthage to build the framework dependencies. I imagine I could have used CocoaPods to do it as well. However, that would have required that I start using a workspace, and I didn't want to have to do that so as to keep changes as minimal as possible.
Also, with Carthage, it didn't require that I add a new Podfile/Podfile.lock, since Carthage will use the existing Cartfile/Cartfile.resolved that's already there. That's because Carthage uses the Cartfile.resolved when using the framework in another project and when building the framework on its own. Whereas, with CocoaPods, *.podspec is used when using the framework in another project but Podfile.lock (if you've added a Podfile) is required to install dependent pods in the framework itself.
This was a very challenging problem to solve, and required a combination of a few solutions pieced together. #EricWasTaken's solution helped, as well as adding:
source 'https://github.com/CocoaPods/Specs.git'
to the top of my Podfile. Then navigating to the Example app and run
pod repo update
pod install
Now the framework I am creating can find the cocoapods my framework requires.

Can't import GoogleCloudMessaging from Cocoapods in Swift

My problem is that I can't import GoogleCloudMessaging, downloaded by podfile, to my Swift project.
My steps:
I installed it by
pod 'GoogleCloudMessaging', '~> 1.2'
http://i.stack.imgur.com/x3rKm.png
2.It has not ".framework", but ".a" file library. So I added this to my Linked Frameworks and Libraries:
http://i.stack.imgur.com/cImxW.png
Also I imported it to my bridging-Header and all is ok, I did not see any errors. Looks like:
#import <GoogleCloudMessaging/GoogleCloudMessaging.h>
So I tried to add library to my AppDelegate with:
import GoogleCloudMessaging
But it shows error "No such module 'GoogleClougMessaging'"
I read some posts about such problem with Google Frameworks, tried to set (changed Google to GoogleCloudMessaging):
"So Instead of adding $(SRCROOT)/Pods (recursive) I added:
"${SRCROOT}/Pods/Google" (recursive) to the Header Search Paths
"${SRCROOT}/Pods/Google" (recursive) to the Framework Search Paths"
But it did not help.
P.S.: sorry, I have not enough reputation to display images in post, so i added links to screenshots
EDIT
God, I did it.
Don't know why, but trying to 'pod Google/CloudMessaging' causes error "Specs satisfying the Google/CloudMessaging dependency were found, but they required a higher minimum deployment target.". But it was 8.0, so this is strange.
Finally I just download my project from my repo with "git clone ..." to new folder and then did "pod install", and all works fine, my 'pod Google/CloudMessaging' was installed successfully. The error with importing dissapeared, and I don't even need to put this library to Linked Frameworks and Libraries, and did not write any import to AppDelegate

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 for the "Charts" framework. Swift 2

I am a newbie when it comes to CocoaPods so please bear with me!
I am looking at the tutorial (https://www.raywenderlich.com/97014/use-cocoapods-with-swift) however this is using the dependency "pod 'Alamofire', '2.0.2'". I have looked online for over a hour now and I can't find what to use for the Charts framework (https://cocoapods.org/?q=charts).
So Far i have done the following steps:
1.
sudo gem install cocoapods
and got the following output:
2.
pod setup --verbose
and got the following output:
3.
open -a Xcode Podfile
and got the following result :
4.
Uncommented "use_frameworks!" and uncommented "platform :ios, '6.0'" and changed it to "platform :ios, '9.0'"
Now i am stuck as i don't know what dependancies i need to use for the charts framework. Apologies if this is a very simple answer!
Thanks in advanced for your help :)
EDIT: After installing the pod files i dragged the 'Charts.xcodeproj file into my project.
When i try and embed binaries i have various options:
When i add them and build i get the following errors:
Hey First you have to decide which chart library You want to use.
Something like this https://github.com/danielgindi/ios-charts
for above chart library you have to use
pod 'Charts'
in your pod file inside the project .
Now your pod file will be something like this
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'Charts'
Now open the terminal and go to your project directory and enter the command
pod install
and you are good to go.
Hope this help you.
Usually there are instructions on what CocoaPod name to use for installation on the GitHub or source code hosting page of the library.
After a pod install command under your correct project directory, you need to exit out of your .xcodeproject and open up the workspace file. This is what you do from now on after a project has a cocoapod dependency. The workspace now contains both your project, and the pods project as a package manager. The pod(s) you installed are there, and must be accessed by importing the name of the CocoaPod (can be seen in folder drop down view in the Pods project).
You do not need to drag anymore files in your own project or embed like before. Make sure to delete those.
If you're still having trouble, can you edit what your current podfile looks like?

Swift and Cocoapods - Missing required module

I am trying to make a Swift framework. This framework depends on two libraries, Alamofire and SwiftyJSON, which are both written in Swift.
I am using CocoaPods to import these libraries in my framework. Here is the content of my Podfile:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'Alamofire', '1.2'
pod 'SwiftyJSON', '2.2'
In my framework, I have a class that imports and uses these two modules:
import Alamofire
import SwiftyJSON
I can run pod install and build my framework successfully!
Now things get tricky when I'm trying to use my framework in a Swift project.
I copy the .framework file into my project.
In the Build Phases of my project's target, I add a Copy Files Phase with "Destination" set to "Frameworks", and add my framework file.
I import my framework in a Swift class of my project:
import MyFramework
The problem is: Xcode keeps telling me
Missing required module 'SwiftyJSON'
And more surprising: if I don't use SwiftyJSON and remove it from my framework (but still use Alamofire)... It works! And I have the same problem with any other lib than SwiftyJSON. Only Alamofire seems to work.
I've already seen some issues, like this one, and tried some things (changing Build Settings, adding the libraries to the Linked Libraries, adding a Bridging Header though I'm not dealing with ObjC) with no effect...
Does anyone have any ideas on how to solve this problem? It's driving me nuts!
EDIT: I'm using Cocoapods v0.37.0.beta.1. Same issue with v0.36.4.
Problem solved after updating Xcode to version 6.3.1.

Resources