Include CocoasMQTT library in swift framework project - ios

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.

Related

How to use Cocoapods in Xcode

I'm a beginner, just getting started with coding in Swift 5 and Xcode. I'm trying to develop a basic iOS app and want to use a cocoapod to my project.
I've managed to successfully install the cocoapod to Xcode and I can see it in Xcode. However, I can't seem to figure out where to add the relevant codes and use it.
For example, can somebody please help me make use of the following Cocoapod; "Gallery'
https://cocoapods.org/pods/Gallery
Many Thanks.
I'm not entirely sure what step you're on, but in general you add a Cocoapod with the following steps:
Add the pod to your Podfile:
pod `Gallery`
Run pod install in your project directory.
Open the generated .xcworkspace file.
Import the library when you need it in a file:
import Gallery

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.

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

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

Include GCM sdk to cocoapod project

I already have a podsfile importing several other projects as frameworks, which works pretty nicely. Unfortunately it is not possible to install the gcm ios library as a framework. What is the way to go here? Just drag and drog the gcm pod into the project?
There's a setup guide for both objective-c and swift on the developers site of gcm, it can be found here - https://developers.google.com/cloud-messaging/ios/client?ver=swift
pod init
Open the Podfile created for your application and add the following:
pod 'Google/CloudMessaging'
Save the file and run:
pod install
This creates an .xcworkspace file for your application. Use this file for all future development on your application.

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