Using Realm Framework in Today extension (CocoaPods) - cocoapods

I am using realm.io as storage for some data. I want to share this data with my Today extension. I am using CocoaPods and I am wondering how I can share that Framework with both targets. My podfile looks like this:
platform :ios, '8.0'
use_frameworks!
pod 'RealmSwift'
pod 'MBProgressHUD'
pod 'Alamofire'
I tried with this and it worked when building to device, but not when building to the iOS simulator. It returned the error 'ld: framework not found Pods':
platform :ios, '8.0'
use_frameworks!
def shared_pods
pod 'RealmSwift'
pod 'Alamofire'
end
target 'App' do
shared_pods
pod 'MBProgressHUD'
end
target 'AppToday' do
shared_pods
end
What am I doing wrong?
Appreciate any help.
Brgds

Your Podfile looks correct and would work on a clean installation. But you found a bug in the user project integration in CocoaPods when migrating between different setups.
Background info
If you don't explicitly specify a target in the Podfile, then CocoaPods will integrate with the first target in your project. This was your app target, which worked correct as long as it was the only one.
But now you're referencing explicitly to the targets. CocoaPods will create separate so called aggregate targets. Those are in the Pods.xcodeproj and named Pods-App and Pods-AppToday. These are static framework targets (from 0.39.beta.5), which are weak linked to your targets to help Xcode finding your dependencies in the Pods project. Because CocoaPods doesn't know anything about the previous Podfile when you run pod install (and it doesn't retain this information in the Podfile.lock), it doesn't remove the old aggregate target, which was named just Pods and it's product reference in your app target.
Resolving the issue
Select your project file in Xcode in the file navigator
Select your app target in the left pane from the targets list
Go to the General tab
Remove Pods.framework from the Linked Frameworks and Libraries pane
Expected state before
How it should look like

platform :ios, '8.0'
use_frameworks!
pod 'RealmSwift'
pod 'MBProgressHUD'
pod 'Alamofire'
Add this line
link_with 'App', 'AppToday'

Related

error in xcode after pod install firebase

I am getting this error in the screenshot after trying to pod install firebase
My xcode version is 8.2
this is the content of my podfile
# Uncomment the next line to define a global platform for your project
platform :ios, '8.0'
target 'Forsa' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for Forsa
pod 'Firebase/Core'
pod 'Firebase/Messaging'
end
You need to open the file that cocoapods created: PROJECTNAME.xcworkspace (instead of the PROJECTNAME.xcodeproj file) to get access to the installed frameworks.
Or like they say in their documentation:
Make sure to always open the Xcode workspace instead of the project
file when building your project:
$ open App.xcworkspace

How to use cocoapods to install alamofire into watchOS app

Here's my podfile:
source 'https://github.com/CocoaPods/Specs.git'
# Uncomment the next line to define a global platform for your project
target 'raceQs' do
platform :ios, '11.1'
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for raceQs
pod 'AppCenter'
pod 'Alamofire'
end
target 'raceQs WatchKit Extension' do
platform :watchos, '4.1'
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for raceQs WatchKit Extension
pod 'Alamofire'
end
I'm opening my project's xcworkspace and getting a compile error:
Developer/Xcode/DerivedData/raceQs-cwycjawfwoosfubowtoymeizvfln/Build/Products/Debug-iphoneos/raceQs.app/Frameworks/Alamofire.framework'
/Users/mac/Library/Developer/Xcode/DerivedData/raceQs-cwycjawfwoosfubowtoymeizvfln/Build/Products/Debug-iphoneos/raceQs.app/Frameworks/Alamofire.framework: bundle format unrecognized, invalid, or unsuitable
In my Xcode project Navigator, the Frameworks/ Pods_raceQs_WatchKit_Extension is displayed in red.
Any assistance would be greatly appreciated.

Pods.framework in red, doesn't exist in DerivedData

I am trying to using Cocoapods 0.39.0 for the dependencies of my project. I have followed the steps, but I end up with a red Pods.framework in my project. If I look at the path where XCode 7.2.1 says it should be, it doesn't exist:
/Users/ajmas/Library/Developer/Xcode/DerivedData/myproject-cskuurnzjrcpcxfoyaceaeepshgt/Build/Products/Debug/Pods.framework
I have looked around at other entries in Stackoverflow, but I am not find anything indicating how the framework should be generated.
The contents of my Podfile are:
source 'https://github.com/CocoaPods/Specs.git'
target 'myproject' do
platform :osx, '10.11'
use_frameworks!
pod 'Alamofire', '~> 3.0'
end
Any ideas?
Edit, also tried with Cocoapods 1.0.0.beta and no change, even after updating the Podfile to confirm to 'target' being a requirement now.
Build your project with "Generic iOS Device" selected.
If this happens it's most likely because you are using <your_project>.xcproject. When you run pod install CocoaPods creates a <your_project.xcworkspace file that you need to use to have dependencies installed via CocoaPods be available when compiling.

Working with Cocoapods + WatchOS 2 target

I have an iOS project with a lot of pods, around twenty. I want to integrate a watchOS 2 app in, but CocoaPods requires that the podspec contain support for watchOS (as seen here: http://blog.cocoapods.org/CocoaPods-0.38/)
At first, I thought I could fork all of the pods that aren't updated, point my podfile to those forked repos, and bob's your uncle. The problem is that some of the pods that I'm using are closed/not-public. Is there a way for me to not build the main application's pods for the watchOS target? Like using target isolation like so?:
target "Watch" do
end
I can't seem to get that ^ potential solution to build, as it still tries to build the pods. I've also tried this repo, no luck: https://github.com/orta/cocoapods-expert-difficulty
There are two way to integrate pods using podfile with WathOS.
1) Add Required pods directly to watch extension as below.
target '<your watch Extension Name>' do
platform :watchos, '2.0'
pod 'RealmSwift'
pod 'Alamofire'
pod 'MMWormhole', '~> 2.0.0'
end
2) Create Shared pods and add to both watch extension and iOS target both.
def sharedPods
pod 'RealmSwift'
pod 'Alamofire'
end
target '<your watch Extension Name>' do
platform :watchos, '2.0'
sharedPods
end
target '<your iOSApp Name>' do
platform :ios, '8.0'
sharedPods
end
Add only watchOS and iOS supported pods in sharedPods,
Do not add pods in sharedPods which does not support watchOS.
e.g.
def sharedPods
pod 'RealmSwift'
pod 'Alamofire'
pod 'otherWatchOS&iOS supported Pod1'
pod 'otherWatchOS&iOS supported Pod2'
end
Add only iOS supported pods in target '<your iOSApp Name>'
e.g.
target '<your iOSApp Name>' do
platform :ios, '8.0'
sharedPods
pod 'otherOnlyiOS supported Pod1'
pod 'otherOnlyiOS supported Pod2'
end
So, this way you can add required pods for required targets.
I've found my problem! I was using Swift for my Watch code, but my parent app is in Obj-c. Thought it wouldn't be a problem except the watch target attempts to compile the Swift bridging header that I use in my main app, which is what was leading to those pods building unnecessarily. So, the solution is either specify a different bridging header for your Watch target or using Obj-c!

WatchKit Extension not working under CocoaPods

Using iOS-8.3, Xcode-6.3.1 and MacOS-10.10.3 - The CocoaPods (v0.37.1) installation of the RealmSwift (v0.92.3) described here and here basically works, except the WatchKit Extension does not find any Realm keywords.
My Podfile looks as follows:
xcodeproj 'MyApp.xcodeproj'
workspace 'MyApp.xcworkspace'
platform :ios, '8.3'
source 'https://github.com/artsy/Specs.git'
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
def shared_pods
pod 'RealmSwift', '>= 0.92.3'
end
target 'MyApp' do
shared_pods
end
target 'MyAppTests' do
shared_pods
end
target 'MyApp WatchKit Extension' do
shared_pods
end
link_with 'MyApp', 'MyApp WatchKit Extension'
All my Realm-keywords in the WatchKit Extension do not work as can be seen in the following error messages (...having commented out any import RealmSwift statements) (see pictures below)
Any idea strongly appreciated of what could still be wrong ???
Any idea on how the target-settings must be. Hint: The NameEntry Realm-Object is used in both targets (i.e. MyApp and also MyApp WatchKit Extension). This seems to add complexity to the CocoaPods usage. Any idea if the double-usage (i.e. in both targets) need a special cocoapods setting ?? What about "import RealmSwift" - is this necessary or not ??
The Podfile above is actually the right one !!
However, it is important that you still "import RealmSwift" in your Realm-Object definition(s) using CocoaPods as can be seen in the corrected example below. This will make your error messages of the WatchKit Extension not recognizing any realm-object go away !
Also, if you intend to use your Realm-Object in two targets (i.e. "MyApp" and "MyApp WatchKit Extension"), make sure you select both the corresponding targets in the target selection pane of your RealmObject.swift file (see image below):

Resources