【问题标题】:Realm installation XCode 8.1领域安装 XCode 8.1
【发布时间】:2016-11-28 20:15:33
【问题描述】:

我很难将 Realm 集成到我的项目中。 实际上,我正在遵循官方文档中的指导方针,尽管这对我没有帮助。

当我尝试导入 RealmSwift 时,我得到“没有这样的模块”。

import RealmSwift

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

这是我的 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

【问题讨论】:

  • 您可以尝试将 Podfile 的 post_install 部分移出 target 'RealmTest' do 部分,然后再次从终端运行 pod install 吗?
  • @AustinZ 也没有帮助
  • 你能构建和运行你的项目吗?这可能会解决问题。第一次编译项目时,即使安装正确,也会出现此错误。
  • @Orlando 这并没有帮助,但已找出主要错误。这很崩溃,因为用 Swift 2.3 编译的模块无法在 Swift 3 中导入。
  • @DanielChepenko 为什么在 XCode 8.1 中使用 Swift 2.3?它不会起作用。

标签: ios xcode realm


【解决方案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

然后重新安装Realm,然后退出Xcode

pod install

从那里使用

.xcworkspace

CocoaPods 生成的用于打开项目的文件。

最后一项是手动将两个文件添加到 Linked Frameworks and Libraries 部分。

通过 .xcworkspace 打开您的项目,在左侧栏中选择您的项目。然后选择右边的General,向下滚动Linked Frameworks and Libraries,添加这两个文件

Realm.framework
RealmSwift.framework

最后一步似乎没有必要,但在我们完成该步骤之前,我们无法让构建工作。

【讨论】:

    【解决方案2】:

    哦! 实际上问题出在 Swift Compiler - 版本中 谁会有类似的问题,尝试去 Build Settings - Swift Compiler - Version - Use Legacy Swift Language Version - 切换到“No”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-24
      • 2017-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多