CocoaPods and Realm in Swift

荒凉一梦 提交于 2020-01-04 02:41:06

问题


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)

  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:

  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!


回答1:


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:

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



来源:https://stackoverflow.com/questions/30428046/cocoapods-and-realm-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!