2016-11-28 70 views
0

我在將Realm集成到我的項目中很困難。 其實,我遵循官方文檔的指導原則,儘管這對我沒有幫助。領域安裝XCode 8.1

當我試圖導入RealmSwift時,我得到了「沒有這樣的模塊」。

import RealmSwift 

在框架中Realm.framework是紅色的。

enter image description here

這裏是我的Podfile

# Uncomment this line to define a global platform for your project 
# platform :ios, '9.0' 

target 'RealmTest' do 
    # Comment this line if you're not using Swift and don't want to use dynamic frameworks 
    use_frameworks! 

    # Pods for RealmTest 
    pod 'RealmSwift' 

    target 'RealmTestTests' do 
    inherit! :search_paths 
    # Pods for testing 
    end 

    target 'RealmTestUITests' do 
    inherit! :search_paths 
    end 

    post_install do |installer| 
    installer.pods_project.targets.each do |target| 
     target.build_configurations.each do |config| 
     config.build_settings['SWIFT_VERSION'] = '2.3' # or '3.0' 
     # Pods for testing 
     end 
    end 
    end 
end 
+0

你可以嘗試移動' 「目標」RealmTest'do'部分的Podfile的post_install'部分,然後再次從終端運行'pod install'? – AustinZ

+0

@AustinZ也沒有幫助 –

+0

你可以建立和運行你的proyect?這可能解決這個問題。第一次編譯該項目時,即使它已正確安裝,也會出現此錯誤。 – Orlando

回答

1

我有一些問題得到它裝好。這可能不是答案,但通過這些工作之後,我的項目是建設:

這裏是我的PodFile類似於

# Uncomment the next line to define a global platform for your project 
# platform :ios, '9.0' 

target 'RealmTest' do 
    use_frameworks! 

    # Pods for RealmTest 
    pod ‘RealmSwift’ 

end 

post_install do |installer| 
    installer.pods_project.targets.each do |target| 
    target.build_configurations.each do |config| 
     config.build_settings['SWIFT_VERSION'] = '3.0' 
    end 
    end 
end 

我不得不更新的CocoaPods

$ sudo gem install cocoapods 

然後再重新安裝境界,退出Xcode然後

pod install 

從那裏使用

.xcworkspace 

CocoaPods生成的文件打開項目。

最後一項是手動將兩個文件添加到鏈接的框架和庫部分。

通過.xcworkspace打開您的項目,在左欄中選擇您的項目。然後在右側選擇常規和向下滾動鏈接的框架和庫,並添加這兩個文件

Realm.framework 
RealmSwift.framework 

這最後一步,似乎沒有必要,但我們不能讓編譯工作,直到我們做了這一步。

1

哦! 其實問題出在Swift編譯器 - 版本號 誰會有類似的問題,試着去編譯設置 - Swift編譯器 - 版本 - 使用傳統的Swift語言版本 - 切換到「否」