I am creating a framework in iOS Using Swift. I have created the podspec file and put the dependency of googlemap in my framework.
When I am trying to install the my framework in sample application,It shows "No Such Module Find" for "GooogleMaps". Please let me how to link google maps in my framework so any application when install my cocoapod will automatically get GoogleMaps without any error.
If you have created a pod and in your .podspec file you are trying to add a dependency (like Alamofire, RealmSwift..) after that you should go to the Example/.. folder and do a pod install to make the dependencies required from the .podspec of your custom pod visible to the .swift files in your custom pod/framework.
A typical example of a pod project folder hierarchy would be:
- SMCustomPod/
- _Pods.xcodeproj
- Example/ // <-- do a pod install under this folder in order to get the dependencies declared in your .podspec
- Podfile
- SMCustomPod.xcodeproj
- SMCustomPod.xcworkspace
- SMCustomPod/
- Classes/ // <-- folder with pod specific logic that also uses Alamofire
- Assets/
- SMCustomPod.podspec // <-- your podspec with dependencies (Alamofire..)
First off try to clean the project by
Command + Shift + Options + K
If I'm not mistaken, GoogleMaps framework is built from Objective-C so if there's still a problem then do the following steps:
Create a bridging header file which you can trigger and setup automatically by creating a dummy Objective-C class in your Swift project. Xcode will then ask you if you would want to create a bridging header, click yes. Delete the dummy class you created after.
Configure the header search path to point the Pods with recursion
Do a clean-build.
try this :-
Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target 'Circle' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for Circle --------->>>>>>>>>. Your Project name
pod 'GoogleMaps'
pod 'GooglePlaces'
end
Related
Specifically:
Created a new project
Setup CocoaPods
To the Pod file under Pods I added a dependency (for ex.AlamoFire)
The main app which consumes the pods can import Alamofire
The local cocoapod which I created and added by using the following lines in the podfile:
target 'SomeValue' do
my_own_pod
pod 'CocoaPod_2', :path => '/LocalPath/To/PodSource'
end
Ran pod install and I added the AlamoFire Framework to the CocoaPod_2 under Pods -> General-> CocoaPod_2-> Linked Libraries & Binaries
At this point I was expecting that importing Alamofire in my CocoaPod_2 will work fine but its not.
Screenshot of the workspace :
MyProject.XCWorkspace
|_MyProject.App
|____Source Code files importing CocoaPod_1 (Embedded using CocoaPod)
|____Source Code files importing CocoaPod_2 (Embedded using CocoaPods, local Pod)
|_Pods
|____Podfile
|____Frameworks
|____Pods
|___CocoaPod_1
|___CocoaPod_1 Source Files
|____Source Code for Local Pod
|___CocoaPod_2
|____File contains statement (import cocoapod_1) <---Gives error ld: framework not found
You need to do the following two additional things:
You need to add a Podfile in your CocoaPod_2 followed by a pod install.
Also, you need to define a CocoaPod_2.podspec file in your CocoaPod_2
folder.
If you add Alamofire in both the Podfile and podspec file of CocoaPod_2, you don't need to add in the main app's Podfile. Only adding CocoaPod_2 entry in the app's Podfile will suffice.
I hope that helps!
I am trying to create a Dynamic Framework to share the code among various extensions of my app.
Problem :
Here is my project structure.
MyFrameworks is a network layer of my app which inherently uses Alamofire. So structured my pod file as follow.
platform :ios, '9.0'
use_frameworks!
workspace 'CocoaPodsProjectworkspace'
def shared_pods
pod 'Alamofire'
pod 'SwiftyJSON'
end
target 'CocoaPodsProject' do
project 'CocoaPodsProject.xcodeproj'
# Pods for CocoaPodsProject
end
target 'MyFramework' do
project 'MyFramework/MyFramework.xcodeproj'
shared_pods
end
target 'CocoaPodsProjectTests' do
end
target 'CocoaPodsProjectUITests' do
end
On building the framework when I drag it as embedded binary to my Main project I get the error.
dyld: Library not loaded: .framework/Alamofire Referenced from:
/Users/sandeep/Library/Developer/Xcode/DerivedData/CocoaPodsProjectworkspace-enpobdyluhbxdwazuvbfogcspfof/Build/Products/Debug-iphonesimulator/MyFramework.framework/MyFramework
Reason: image not found
Solutions I tried :
Declaring the pods_frameworks.framework as optional in linked
binaries.
Tried changing RunPath Search path of framework Dynamic Library
Install name Running pod deintegrate and running pod install again.
Deleting derived data and relinking framework all lead to same
problem.
Solution that worked :
I realized that MyFramework.framework was trying to find the Alamofire.framework in a wrong directory and it was alway trying to search relative to project/target using the framework . So the simplest solution that I could find was to modify pod file as follow.
platform :ios, '9.0'
use_frameworks!
workspace 'CocoaPodsProjectworkspace'
def shared_pods
pod 'Alamofire'
pod 'SwiftyJSON'
end
target 'CocoaPodsProject' do
project 'CocoaPodsProject.xcodeproj'
shared_pods
# Pods for CocoaPodsProject
end
target 'MyFramework' do
project 'MyFramework/MyFramework.xcodeproj'
shared_pods
end
target 'CocoaPodsProjectTests' do
end
target 'CocoaPodsProjectUITests' do
end
As you can see I added the shared_pods to both main app and my framework project and their respective targets. Now everything works smooth. I neither had to make pods_framework optional nor had to modify the build settings of MyFramework.
Question:
Adding the shared repos to all the projects and their targets which wants to use my framework looks little redundant. Is there a better way I can specify Myframework.framework to read all its dependencies rather than reading from project using it?
I have raised a issue for the same on CocoaPods Git repo. But because it isn't inherently a issue they might not revert back. Hence posting it as a question here.Link to issue : https://github.com/CocoaPods/CocoaPods/issues/6901 if it helps.
Solved it by creating a cocoa pod for my custom Framework and using cocoa pods dependency .
Step 1 : Clean the Main/Parent project
Removed MyFramework from the project (which was added as sub
project) and remove MyFramework.framework added in embedded library of projects General settings.
Run pod deintegrate (to de-integrate the pod already added to
project)
Now that the project is clean and does not have any pod added
initialized the pod by running pod init
Step 2: Create a Pod for my Framework
Using cd command navigate to MyFramework project and once you are in
MyFramework's root folder run pod spec create MyFramework
This will create a file named MyFramework.podspec in the
MyFramework's root folder. Open MyFramework.podspec using any of the
editor tool and update it as shown in tutorial https://www.raywenderlich.com/126365/ios-frameworks-tutorial
Most important step which is not there in this tutorial is how to add
cocoa pods dependency that our framework needs to build. Turns out
thats the most easiest part. In my case I needed SwiftyJSON and
Alamofire so in .podspec file I added,
s.dependency 'Alamofire'
s.dependency 'SwiftyJSON'
Step 3:
Now open the Main/Parent projects Podfile and update it as shown
below.
target 'CocoaPodsProject' do
use_frameworks!
pod 'TestFramework', :path => 'TestFramework/'
end
What it did is, it tells main project to add TestFramework as dependency and installs TestFramework in Framework folder of main project. Because TestFramework in itself has dependency to Alamofire & SwiftyJSON when you run pod install it will not only install Alamofire but also installs SwiftyJSON and adds it to TestFramework's Framework folder.
Thats all. Now your TestFramework can access Alamofire and SwiftyJSON and Main/Patent project can access TestFramework
If you want to now update TestFramework code, till u finish develop add it as subproject to Main project (This is necessary because if you open TestFramework.xcproj u won't see Alamofire/Swifty JSON. You have to open the Parent project's workspace itself hence this solution). Once u are done with development if u decide to remove the TestFramework as subproject u can do that :)
Finally If you decide to add additional extensions to app, Lets say u add Today extension all u have to do is to modify ur Podfile as follow.
target 'CocoaPodsProject' do
use_frameworks!
pod 'TestFramework', :path => 'TestFramework/'
end
target 'CocoapodsToday' do
use_frameworks!
pod 'TestFramework', :path => 'TestFramework/'
end
Woo hooo :) Now add your frameworks to as many extensions you want :) Hope it helps.
I'm using switf and pods. When i type 'pod install' on my terminal, Instead of having the frameworks downloaded to my project, i get the files.
This makes no difference to me, except for the fact that when i want to import them in my project, i always get an error saying they can't be found.
Here is my pod file
# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
# Uncomment this line if you're using Swift
use_frameworks!
target 'Project' do
pod 'MSSTabbedPageViewController'
pod 'PageMenu'
end
As ocarol stated, import the framework. However, before importing at the top of the file you want to use the framework, build the project, as Xcode seems to not link the pod's to the project automatically.
Also open the .xcworkspace file that pod install generates.
You use these libraries as frameworks (use_frameworks!). So you have to import the framework at the top of the Swift file, like:
import MSSTabbedPageViewController
if had created a bridging header file, you can import the framework in it.
Following are the steps I did to add Parse using CocoaPods but still getting unresolved error.
Added Pods File:
# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
pod 'Parse'
target 'GroomCal' do
end
target 'GroomCalTests' do
end
target 'GroomCalUITests' do
end
After that I did pod install. Parse and Bolts frameworks got installed (I can see them in XCode).
I then added -Bridging-Header.h and added #import <Parse/Parse.h>to it.
When I try to import Parse in AppDelegate.swift file, I still get No such Module Parse error message. What am I missing here.
I did use the *.xcworkspace file to open the project too.
To use cocoapods with swift you need to add the flag
use_frameworks! to the podfile as swift doesn't allow to add static libraries.
source Cocoapods blog
I have just started a new Swift project and I would like to use different libraries. In particular, I would like to use Realm.io, an Obj-C library. But, I would also like to use pure Swift libraries such as Alamofire or Dollar.
I use Cocoapods for managing my dependencies. I use the latest version (0.37.0) and the new use_frameworks! flag. pod install is successful anytime.
Unfortunately, when I try to build my project I get two errors (for my main target):
Umbrella header Realm.h not found from module.modulemap
Could not build Objective-C module Realm from any file using import Realm
Other imports work fine.
I have noticed the following: if I remove pure Swift libs and use_frameworks, everything works fine. I am aware about this current issue from Cocoapods. However, it should not be a problem for Realm asks developers to use that flag.
Here is my Podfile:
platform :ios, '8.0'
use_frameworks!
target 'rothrock' do
pod 'Realm'
pod 'Cent'
pod 'SwiftyJSON'
pod 'Alamofire'
end
target 'rothrockTests', :exclusive => true do
end
I use no bridging header. Should I?
Any idea or workaround?
Alright, here is the full walkthrough:
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.
You need a bridging header and import your Objective-C library headers there.
If you are using only Realm you can check out this documentation for Swift http://realm.io/docs/cocoa/ (go to CocoaPods down in the tabs)
Swift
Install CocoaPods 0.36.0 or later ([sudo] gem install cocoapods).
In your Podfile, add use_frameworks! and pod 'Realm' to your app target.
From the command line, run pod install.
Use the .xcworkspace file generated by CocoaPods to work on your project!
Download the latest release of Realm and extract the zip.
Drag the file at Swift/RLMSupport.swift into the File Navigator of your Xcode project, checking the Copy items if needed checkbox.
I just installed the Realm library in a project I have with some of the libraries you mention above like Alamofire and SwiftyJSON and others and it works fine when you build the project and even put the import Realm, no compilation errors at all.
I'm using Cocoapods 0.36.0, the stable version and this is my PodFile :
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
platform :ios, '8.0'
link_with 'ApiWorkflow', 'ApiWorkflowTests'
pod 'SwiftyJSON', '~> 2.2'
pod 'Alamofire', '~> 1.2'
pod 'Typhoon', '~> 3.0'
pod 'SwiftCSV', '~> 0.1'
pod 'Realm'
I hope this help you