Swift中的CocoaPods和Realm [英] CocoaPods and Realm in Swift
问题描述
我使用Xcode-6.3.1,iOS-8.3和MacOS-10.10.3,试图使用RealmSwift(0.92.3)和CocoaPods 0.37.1
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
我使用以下过程:
-
在终端中安装cocoapods:
install cocoapods (in terminal):
$ sudo gem install cocoapods
创建一个新的Xcode项目(名为MyApp)
Create new Xcode project (named MyApp)
创建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
将Podfile放入MyApp文件夹(位于MyApp.xcodeproj旁边)
Place the Podfile in the MyApp folder (next to MyApp.xcodeproj)
下载最新的Realm(从此处)下载0.92.3)(即Swift版本)
Download the newest Realm (0.92.3 from here) (i.e. Swift version)
- 解压缩
- 转到/ios文件夹
- 还将RealmSwift.framework复制到您的MyApp-project文件夹中
(在第4点和第5点之后,您最终会像此处的图片一样结束)
(after Point 4 and 5 you end up like in the picture here)
-
在终端内,转到MyApp文件夹并键入
Inside a terminal, go to your MyApp-folder and type
pod install
在pod安装之后,我在终端中看到以下文本:
After pod-install, I end up with the following text inside the terminal:
- 之后,我只需打开新的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!
推荐答案
我终于发现,缺少红色的红色"框架没有什么害处.使用CocoaPods这些框架实际上并不存在-因此Xcode无法更改颜色.可以肯定的是,这里并没有表示错误...
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...
以上工作流程(第1-8页)正确无误!
THREFORE THE ABOVE WORKFLOW (pt 1-8) IS CORRECT !
但是,如果您想使用"MyApp WatchKit Extension",则上面的Podfile不合适.正确的是:
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
此外,同样重要的是,仍要在Realm-Object定义中导入RealmSwift",如以下示例所示:
Also, it is important that you still "import RealmSwift" in your Realm-Object definition(s) as can be seen in an example below:
此外,如果打算在两个目标(即"MyApp"和"MyApp WatchKit Extension")中使用Realm-Object,请确保在RealmObject.swift文件的目标选择窗格中选择了两个相应的目标(参见下图):
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):
这篇关于Swift中的CocoaPods和Realm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!