I have an Objective-C project.
Most of files are written in Objc
Several custom UIView classes are written in Swift.
Specially one of UIViewController subclass using Core-Plot is written in Objc.
It has no problem, until...
Now, I am trying to create a new UIViewController using Core-Plot written in Swift.
Trying to use import CorePlot to import external framework Core-Plot as described here. But the compiler shows the error "No such module 'CorePlot'"
Here is my Podfile:
platform :ios, '8.0'
target 'Meters' do
# use_frameworks!
# Pods for Meters
pod 'PQFCustomLoaders', '~> 1.1.0'
pod 'CorePlot'
end
I have used pod install and 'pod update'
I tried "Clean and rebuild"
Neither works for me. Please let me know if any other information needed.
You have to build pods as frameworks (uncomment use_frameworks! in the pod file) to create modules. Core Plot will work fine that way but I don't know about the other pod you're using.
Related
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
My iOS app contains both objective-C and Swift code. Now i have added use_frameworks! at the top of pod file to use some swift library. Unfortunately it started giving compilation errors.
My pod version : 0.39.0
It started complaining about imports in bridge.h file
Pod file contains objective-C libraries. Now i want to add swift libraries.
How can i fix this issue. Let me know if needs more details
use_frameworks!
platform :ios, '9.0'
xcodeproj 'Test.xcodeproj'
def devDependecies
pod 'SocketRocket'
pod 'CocoaLumberjack'
pod 'MRProgress'
pod 'GRMustache', '~> 7.3.0'
pod 'Realm', '=0.96.2'
pod 'ADALiOS'
pod 'Office365/Outlook'
pod 'Office365/Discovery'
pod 'AFNetworking'
#https://github.com/youtube/youtube-ios-player-helper/issues/160
pod 'youtube-ios-player-helper', :git=>'https://github.com/youtube/youtube-ios-player-helper', :commit=>'head'
pod 'iOSCalendarEventParser', '=0.0.4'
pod 'OneDriveSDK'
end
target 'Test' do
devDependecies
end
Sample error in bridge.h file :
But this file exists under pod directory.
'youtube-ios-player-helper' can compile as a framework.
So remove it from the bridge header and just add an import line in your Swift classes
import youtube-ios-player-helper
Do the same for all pods that can compile as a framework
At this moment Xcode does not allow that. use_frameworks works only with swift pods or libraries. If you add an objective C library you need to use the bridging header, therefore you need to remove the use_frameworks instruction in order to make it work. The only work around I found is to only import through pods the objective C libraries and the swift libraries you can add them manually. You can copy the classes names and content and use them as if you would have created them.
I'm creating a new Cocoa Touch Framework (MyFramework.framework), which will have a dependency on Alamofire. This framework will be written in Swift. As a test I started a new Cocoa Touch Framework project:
File > New > Project > Framework & Library > Cocoa Touch Framework
Then, in the terminal I performed:
pod init
under this projects directory. In the newly created Podfile I added the following:
source 'https://github.com/CocoaPods/Specs.git'
# 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!
pod 'Alamofire', '~> 3.0'
Once again, in the Terminal I performed:
pod install
and started coding away.
Everything seemed well and good till I used the MyFramework.framework Product in a Single View Project. When I attempt to run the project I get the following issue:
dyld: Library not loaded: #rpath/Alamofire.framework/Alamofire
Referenced from: /Users/me/Library/Developer/CoreSimulator/Devices/87DA70B6-49BF-441E-BD81-F4A80B0792CF/data/Containers/Bundle/Application/2E414EA8-7E54-4D71-9295-566D4FAAADE2/test.app/Frameworks/MyFramework.framework/MyFramework
Reason: image not found
I thought that Cocoa Touch Framework projects were inherently Dynamic, and therefore would include all dependencies.
Can anyone tell me why this is happening and how I may be able to fix it?
Is this an issue with CocoaPods or am I missing something?
I'm a noob to Stack Overflow so please let me know if you need more information from me.
Thanks!
Unfortunately CocoaPods doesn't support use with Cocoa Touch Framework target. I found a few references to this while digging through their issues on GitHub:
We don't really support integrating Pods into framework targets...
-neonichu on Nov 4, 2015
and
...in order for this to "just work", CP would need to do a recursive analysis of dependencies in your Xcode project and also somehow ensure that you would never use the build product in another context.
-neonichu on Jul 7, 2015
So far I've found two ways to deal with the issue:
The right way is to create a new pod spec for your framework and bring it in to your main project via CocoaPods. This resolves all of the problems CococaPods has with the dependency graph and is the recommended solution from the CocoaPods developers.
The easy way is to include the pods from your framework in your main project. This seems to work, but frankly I don't know why. This is the Podfile from my test project:
platform :ios, '9.0'
use_frameworks!
def myfirstframework_pods
pod 'Alamofire', '~> 3.0'
end
target 'MyApp' do
pod 'SwiftKeychainWrapper', '~>1.0'
myfirstframework_pods
end
target 'MyFirstFramework' do
myfirstframework_pods
end
Try adding the dependency on Alamofire in the framework's podspec as below
Pod::Spec.new do |s|
# Other setup
# Dependencies
s.dependency "Alamofire"
# Other dependencies if any
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
I'm using Typhoon library for Dependency Injection Framework. I use CocoaPod for installing this library. Here is my pod file:
target "typhoon-swift-demo" do
pod 'Typhoon'
end
target "typhoon-swift-demoTests" do
end
I have installed successfully but when I open workspace project file. I type those line of code as Typhoon sample code:
public class ApplicationAssembly: TyphoonAssembly {
}
I meet error that my application doesn't recognize TyphoonAssembly I have tried to use some lines such as:
import Typhoon // not recogize typhoon
import TyphoonAssembly // not regconize
Please tell me how to fix this problem. What should I add before I can use library. Thanks :)
You have to import the Pod header files using Objective-C and not Swift. So you'll be mixing the two languages if you want to use CocoaPods with Swift. Here's a great tutorial on how to accomplish this.
In addition to Quark's answer, The Typhoon Swift example shows how to set up Typhoon for usage with Swift and CocoaPods.
Note that if you're using "application-style" tests, which is the default almost everywhere now, then the test target will already implicitly have the main target's dependencies. Therefore the test target should be declared exclusive. Example:
platform :ios, '7.0'
target :PocketForecast, :exclusive => true do
pod 'Typhoon', :head
pod 'CKUITools'
pod 'ICLoader'
pod 'NGAParallaxMotion'
pod 'NSURL+QueryDictionary'
pod 'OCLogTemplate'
pod 'PaperFold', :git => 'https://github.com/jasperblues/PaperFold-for-iOS.git', :tag => '1.2-no-gesture-recognizers'
end
target :PocketForecastTests do
pod 'Expecta', '~> 0.2.1'
pod 'OCHamcrest'
pod 'OCMockito'
end
inhibit_all_warnings!
If the test target is not declared exclusive, then it will have all of the application's libraries linked twice. This can cause problems in Typhoon's case, as it uses a lot of introspection.
Also note in the sample application, that there is a bridging header, that includes:
#import "Typhoon.h"
Typhoon Swift Example:
I think this needs an update. I have started recently developping Swift applications and, coming from a Java background, searched for a framework like Spring.
The best I found is Typhoon. I didn't find a good introduction for newbies however, so I made a scratch project to try it out.
I integrated Typhoon by:
Installing cocoapods
Creating a basic podfile with a "use_frameworks!" line like here
pod install
Adding the "TyphoonInitialAssemblies" array to my plist file
Create a first assembly and add it to the array in the plist
In the assembly,
import Typhoon
public class MyAssembly:TyphoonAssembly{}
Works like a charm!
You have even met this error.
I fixed by way:
=> remove "platform :ios, 'x.0'"
use_frameworks!
target 'LateManagement' do
pod 'Alamofire'
pod 'SwiftyJSON'
end