fisher
fisher

Reputation: 1296

Using Realm Framework in Today extension (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

Upvotes: 1

Views: 581

Answers (2)

marius
marius

Reputation: 7806

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

Both aggregate target products: the old to remove and the new to keep

How it should look like

Just the new aggregate target product

Upvotes: 1

Masterfego
Masterfego

Reputation: 2678

platform :ios, '8.0'
use_frameworks!

pod 'RealmSwift'
pod 'MBProgressHUD'
pod 'Alamofire'

Add this line

link_with 'App', 'AppToday'

Upvotes: 0

Related Questions