简体   繁体   中英

Can't install Realm library via CocoaPods in Swift 2.0

I am making iOS app in Swift2.0.

I tried to install Realm library via CocoaPod.

It is fine when I execute 'pod install' in command line.

But in Xcode project, I can't build my iOS app.

There is an error and stop to build.

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)

It's my Podfile

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

What should I do to install Realm?

Thanks!

You might be seeing this error because using the RealmSwift pod is not supported in mixed Objective-C/Swift Apps. Try using the Objective-C Realm pod:

pod 'Realm'

You'll still be able to use Realm in your Swift files, you'll just have to convert the Objective-C syntax to Swift and, of course, the Swift only stuff in RealmSwift won't be available.

If your project was in Swift you you would have to install RealmSwift to use the full swift features:

pod 'RealmSwift'

In your code you have to import both Realm and RealmSwift to use all features:

import Realm
import RealmSwift

EDIT:

I updated this answer. Thanks to Donamite for pointing out that you only need to have `RealmSwift' in the podfile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM