iKK
iKK

Reputation: 7012

CocoaPods and Realm in Swift

Using Xcode-6.3.1, iOS-8.3 and MacOS-10.10.3, I am trying to use RealmSwift (0.92.3) and CocoaPods 0.37.1

I use the following procedure :

  1. install cocoapods (in terminal):

     $ sudo gem install cocoapods
    
  2. Create new Xcode project (named MyApp)

  3. Create Podfile

    platform :ios, '8.3'
    use_frameworks!
    
    target 'MyApp' do
      pod 'RealmSwift', '>= 0.92.3'
    end
    
    target 'MyAppTests' do
      pod 'RealmSwift', '>= 0.92.3'
    end
    
  4. Place the Podfile in the MyApp folder (next to MyApp.xcodeproj)

  5. Download the newest Realm (0.92.3 from here) (i.e. Swift version)

    • unzip it
    • go to /ios folder
    • copy RealmSwift.framework also to your MyApp-project folder

(after Point 4 and 5 you end up like in the picture here)

enter image description here

  1. Inside a terminal, go to your MyApp-folder and type

        pod install
    
  2. After pod-install, I end up with the following text inside the terminal:

enter image description here

  1. After that, I simply open the new MyApp.xcworkspace

It basically looks ok - except: NO FRAMEWORK SEEMS TO BE FOUND !! (see screenshot below)...

What am I still missing ????

Any help greatly appreciated!

enter image description here

Upvotes: 4

Views: 9260

Answers (1)

iKK
iKK

Reputation: 7012

I finally found out that the "red" colored missing frameworks are no harm. Using CocoaPods these frameworks are not physically there - therefore Xcode cannot change the color. It, for sure, does not indicate a mistake here...

THREFORE THE ABOVE WORKFLOW (pt 1-8) IS CORRECT !

However, the Podfile above is not the right one if you want to use your "MyApp WatchKit Extension". The correct one is:

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!
link_with 'MyApp', 'MyApp WatchKit Extension'

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

Also, it is important that you still "import RealmSwift" in your Realm-Object definition(s) as can be seen in an example below:

enter image description here

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):

enter image description here

Upvotes: 6

Related Questions