如何使用Swift 4的领域?

时间:2023-01-22 16:27:50

I'm trying to run my current project in the new Xcode 9 beta, but when I do so it says Module compiled with Swift 3.1 cannot be imported in Swift 4.0. How can I solve this problem? I'm not using cocoapods.

我正在尝试在新的Xcode 9 beta中运行当前项目,但当我这么做时,它说用Swift 3.1编译的模块不能在Swift 4.0中导入。我如何解决这个问题?我不使用cocoapods。

2 个解决方案

#1


15  

Update: As of v2.10.1, released 2017-09-14, Realm's prebuilt binaries include frameworks built with Xcode 9 for Swift 3.2 and 4.0. It's no longer necessary to build them yourself.

更新:截至2017-09-14发布的v2.10.1,领域的预构建二进制文件包括使用Xcode 9为Swift 3.2和4.0构建的框架。不再需要自己构建它们。

The information below remains relevant to anyone looking to use Realm with prerelease versions of Xcode in the future.

以下信息仍然适用于任何希望将来使用带有Xcode预发行版本的领域。


If you're currently integrating Realm's prebuilt binaries, you'll need to switch to building Realm from source in order to support Swift 3.2 and 4.0, as Realm does not publish prebuilt binaries for prerelease versions of Xcode. You can build Realm from source in one of three ways:

如果您目前正在集成领域的预构建二进制文件,您将需要从源代码切换到构建领域,以便支持Swift 3.2和4.0,因为领域没有为Xcode的预发布版本发布预构建的二进制文件。你可以通过以下三种方式之一从源建立领域:

  1. Using CocoaPods.

    使用CocoaPods。

    CocoaPods always builds dependencies from source.

    茧类动物总是从源头建立起依赖关系。

  2. Using Carthage.

    使用迦太基。

    By default Carthage will attempt to download prebuilt binaries, but will fall back to building from source if the prebuilt binaries are for a different Swift version than the version of Xcode in use.

    默认情况下,Carthage将尝试下载预构建的二进制文件,但如果预构建的二进制文件用于与正在使用的Xcode版本不同的Swift版本,则将回到从源代码构建。

  3. Build Realm manually from source, and then integrate the built frameworks as you would the prebuilt binaries that Realm provides.

    从源代码手动构建领域,然后像集成领域提供的预构建二进制文件一样集成构建框架。

    You can do this by checking out a release tag from Git:

    您可以通过查看Git的发布标记来实现这一点:

    git clone --recursive https://github.com/realm/realm-cocoa.git
    cd realm-cocoa
    git checkout v2.10.0
    

    Then run whichever of the following commands corresponds to the platform you care about to build the Realm Swift framework for that platform:

    然后运行以下命令中的任何一个对应于您所关心的平台,以构建该平台的领域Swift框架:

    REALM_SWIFT_VERSION=4.0 sh build.sh ios-swift
    REALM_SWIFT_VERSION=4.0 sh build.sh osx-swift
    REALM_SWIFT_VERSION=4.0 sh build.sh watchos-swift
    REALM_SWIFT_VERSION=4.0 sh build.sh tvos-swift
    

    The built frameworks will be placed in the build directory within the Realm source, where you can then integrate them as you did the prebuilt binaries that Realm provides.

    所构建的框架将被放置在域源的构建目录中,在那里您可以将它们集成到您所做的领域提供的预构建的二进制文件中。

    These built frameworks should also work with apps using Swift 3.2 due to it using the same compiler as Swift 4.0.

    由于使用与Swift 4.0相同的编译器,这些构建框架还可以使用使用Swift 3.2的应用程序。

#2


2  

As a followup to bdash's item 3 about how to build Realm manually from source, and to answer addzo's question about the xcodebuild error (that I ran into as well): Be sure that the iPhone 6 simulator is set up for your Xcode 9 to avoid that error. I suppose Realm's build scripts must target it. This solved it for me, anyhow.

关于bdash关于如何从源代码手动构建领域的第3项,以及回答addzo关于xcodebuild错误(我也遇到过)的问题:请确保为您的Xcode 9设置了iPhone 6模拟器,以避免该错误。我认为领域的构建脚本必须针对它。不管怎么说,这解决了我的问题。

#1


15  

Update: As of v2.10.1, released 2017-09-14, Realm's prebuilt binaries include frameworks built with Xcode 9 for Swift 3.2 and 4.0. It's no longer necessary to build them yourself.

更新:截至2017-09-14发布的v2.10.1,领域的预构建二进制文件包括使用Xcode 9为Swift 3.2和4.0构建的框架。不再需要自己构建它们。

The information below remains relevant to anyone looking to use Realm with prerelease versions of Xcode in the future.

以下信息仍然适用于任何希望将来使用带有Xcode预发行版本的领域。


If you're currently integrating Realm's prebuilt binaries, you'll need to switch to building Realm from source in order to support Swift 3.2 and 4.0, as Realm does not publish prebuilt binaries for prerelease versions of Xcode. You can build Realm from source in one of three ways:

如果您目前正在集成领域的预构建二进制文件,您将需要从源代码切换到构建领域,以便支持Swift 3.2和4.0,因为领域没有为Xcode的预发布版本发布预构建的二进制文件。你可以通过以下三种方式之一从源建立领域:

  1. Using CocoaPods.

    使用CocoaPods。

    CocoaPods always builds dependencies from source.

    茧类动物总是从源头建立起依赖关系。

  2. Using Carthage.

    使用迦太基。

    By default Carthage will attempt to download prebuilt binaries, but will fall back to building from source if the prebuilt binaries are for a different Swift version than the version of Xcode in use.

    默认情况下,Carthage将尝试下载预构建的二进制文件,但如果预构建的二进制文件用于与正在使用的Xcode版本不同的Swift版本,则将回到从源代码构建。

  3. Build Realm manually from source, and then integrate the built frameworks as you would the prebuilt binaries that Realm provides.

    从源代码手动构建领域,然后像集成领域提供的预构建二进制文件一样集成构建框架。

    You can do this by checking out a release tag from Git:

    您可以通过查看Git的发布标记来实现这一点:

    git clone --recursive https://github.com/realm/realm-cocoa.git
    cd realm-cocoa
    git checkout v2.10.0
    

    Then run whichever of the following commands corresponds to the platform you care about to build the Realm Swift framework for that platform:

    然后运行以下命令中的任何一个对应于您所关心的平台,以构建该平台的领域Swift框架:

    REALM_SWIFT_VERSION=4.0 sh build.sh ios-swift
    REALM_SWIFT_VERSION=4.0 sh build.sh osx-swift
    REALM_SWIFT_VERSION=4.0 sh build.sh watchos-swift
    REALM_SWIFT_VERSION=4.0 sh build.sh tvos-swift
    

    The built frameworks will be placed in the build directory within the Realm source, where you can then integrate them as you did the prebuilt binaries that Realm provides.

    所构建的框架将被放置在域源的构建目录中,在那里您可以将它们集成到您所做的领域提供的预构建的二进制文件中。

    These built frameworks should also work with apps using Swift 3.2 due to it using the same compiler as Swift 4.0.

    由于使用与Swift 4.0相同的编译器,这些构建框架还可以使用使用Swift 3.2的应用程序。

#2


2  

As a followup to bdash's item 3 about how to build Realm manually from source, and to answer addzo's question about the xcodebuild error (that I ran into as well): Be sure that the iPhone 6 simulator is set up for your Xcode 9 to avoid that error. I suppose Realm's build scripts must target it. This solved it for me, anyhow.

关于bdash关于如何从源代码手动构建领域的第3项,以及回答addzo关于xcodebuild错误(我也遇到过)的问题:请确保为您的Xcode 9设置了iPhone 6模拟器,以避免该错误。我认为领域的构建脚本必须针对它。不管怎么说,这解决了我的问题。