简体   繁体   中英

Module compiled with Swift 4.0 cannot be imported in Swift 3.1 for framework binary

I compiled a framework binary with xcode 9 (swift version 3.2). And I also want to make it work with xcode 8.3.3 with swift 3.2 syntax. But I kept getting Module compiled with Swift 4.0 cannot be imported in Swift 3.1 error message when I attempted to run a project with the framework that was compiled with xcode 9. Which option should I add in order to make this work? I know this is possible because pod Intercom works under both xcode 8.3.3 and 9. I'll appreciate any advice

You cannot use a module compiled using a newer version of Swift in a project that is using an older version of Swift for obvious reasons. The framework compiled using the newer Swift version might be using the newer Swift syntax and/or APIs that only became available in the newer Swift version and hence you wouldn't be able to call any functions from the framework that use newer syntax or APIs. This issue is due to the fact that Swift is not yet ABI stable. See the ABI Stability Manifesto for more information on the topic.

Swift 3.2 was only introduced as part of Xcode9 to make Swift3->4 conversion easier. Xcode8.3.3 only supports Swift 3.1, while Xcode9 only supports Swift 3.2 and above, so you cannot compile your framework to be usable in both major Xcode versions.

If you want to support both Xcode8 and Xcode9 in a binary release of your framework, you would need to provide different versions compiled using different Swift compiler versions. As for dynamic frameworks using Cocoapods/Carthage, you can use conditional compilation blocks like #if swift(>=3.2) to write code that's compatible with multiple versions of the Swift compiler. For more information, see The Swift Programming Language (Swift 4) - Version compatibility .

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