无法在 Swift 2.0 中通过 CocoaPods 安装 Realm 库

Can't install Realm library via CocoaPods in Swift 2.0

我正在用 Swift2.0 制作 iOS 应用程序。

我尝试通过 CocoaPod 安装 Realm 库。

在命令行执行'pod install'就可以了

但是在 Xcode 项目中,我无法构建我的 iOS 应用程序。

出现错误,停止构建。

error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool: can't open file: /Users/satoutakeshi/Library/Developer/Xcode/DerivedData/AlermMA-hczduhcpoaudvlgzjrzioeecipfh/Build/Products/Debug-iphonesimulator/AlermMA.app/Frameworks/Realm.framework/Realm (No such file or directory)

这是我的 Podfile

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'RealmSwift'

我应该如何安装 Realm?

谢谢!

您可能会看到此错误,因为在混合 Objective-C/Swift 应用程序中不支持使用 RealmSwift pod。尝试使用 Objective-C 领域 pod:

pod 'Realm'

您仍然可以在 Swift 文件中使用 Realm,您只需将 Objective-C 语法转换为 Swift,当然,Swift 只有 RealmSwift 中的内容不可用。

如果您的项目在 Swift 中,则必须安装 RealmSwift 才能使用完整的 swift 功能:

pod 'RealmSwift'

在您的代码中,您必须同时导入 Realm 和 RealmSwift 才能使用所有功能:

import Realm
import RealmSwift

编辑:

我更新了这个答案。感谢 Donamite 指出您只需要在 podfile 中包含“RealmSwift”。