对闭源的模块稳定性和库演化支持
[ABI]
Swift v5.0引入稳定的ABI
Swift v5.1 发货 Module stability 和 Library evolution support 适用于闭源(二进制)框架(库)(框架与消费者分开构建)
检查 Swift 版本:
Swift Language Version(SWIFT_VERSION)
要启用它,您应该使用 v11 的 Xcode:
为分发构建库 (BUILD_LIBRARY_FOR_DISTRIBUTION)
Select framework target -> Build Settings -> Build Libraries for Distribution (BUILD_LIBRARY_FOR_DISTRIBUTION) -> Yes
swiftc 标志:
-enable-library-evolution
-emit-module-interface
此设置生成.swiftinterface
Swift 模块接口 (.swiftinterface)
Swift Module 使用与 Objective-C 模块相同的方法 - precompiled binary 或 Compiled Module。
Swift Module Interfaces 是模块公共 API 的文本表示。它是 Swift 对 Objective-C 的标头 .h 文件的替代品。
//previously
consumer(app) -> import Module -> producer(framework) .swiftmodule
//using .swiftinterface
consumer(app) -> import Module -> .swiftinterface -> producer(framework) .swiftmodule
尽管.swiftmodule 是可以更改的,你可以在哪里获得
Module compiled with _ cannot be imported by the _ compiler
.swiftinterface 是稳定的,当有变化时不需要更新(例如 Swift 版本)
没有假设
它位于下一个文件夹中
<framework_name>.framework/Modules/<framework_name>.swiftmodule
看起来像:
// swift-interface-format-version: 1.0
// swift-compiler-version: Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)
// swift-module-flags: -target x86_64-apple-ios12.2-simulator -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -Onone -module-name UtilsSwiftFramework
import Foundation
import Swift
@_exported import UtilsSwiftFramework
@_inheritsConvenienceInitializers @objc public class GFISClassA : ObjectiveC.NSObject {
@objc public static var shared: UtilsSwiftFramework.GFISClassA
@objc public func GFISprintHelloWorld()
@objc public func GFISprintHelloWorld(arg1: Swift.String, arg2: Swift.String)
@objc deinit
@objc override dynamic public init()
}
如您所见,它还包含:
swift-interface-format-version
swift-compiler-version
swift-module-flags
*如果你使用dynamic而不使用@objc[About],你会得到下一个错误
Marking non-'@objc' Swift declaration 'dynamic' in library evolution mode is not supported
XCFramework[About] 强制你使用它
Apple 建议将 .swiftinterface 用于闭源,Swift Package Manager[About] 用于开源