问题
The CocoaPods installation of the RealmSwift Kruherson recommended here (or also is recommended from the realm.io page here) basically works - however there is one problem that is remaining in my App using Swift 0.92.3:
The following import is no longer recognized !
import RealmSwift
What do I still need to do in order to make CocoaPods work under Swift ?
Here is the content of my Podfile used :
platform :ios, '8.3'
use_frameworks!
xcodeproj '/Users/XXX/.../MyApp/MyApp.xcodeproj'
target 'MyApp' do
pod 'RealmSwift', '>= 0.92.3'
end
Here a screenshot of my Xcode project (only Pods part) looks like after the "pod install" :

There are a few "red things" - might the problem lie here or what do I still miss ?
What do I need to do in order to get import RealmSwift
working again ??
回答1:
The "red" color of all the Pod-frameworks is no harm! The frameworks are not physically there - therefore Xcode cannot change the color. It, for sure, does not indicate a mistake here...
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/30425854/import-realmswift-no-longer-working-using-cocoapods