Sai*_*ira 6 xcode abi ios swift
About a year ago, if you wanted to use Swift 4.2 for iOS development, you would have to install Xcode 10, which meant that you used iOS 12 SDK. As part your apps deployment, Swift 4.2 runtime would automatically be bundled with your app binary. This would mean that user installing your app would essentially download a copy of that Swift runtime that will enable your app work.
However, ABI stability came with Swift 5, and you no longer needed to bundle a runtime if your deployment target was iOS 12.2, since the runtime was now part of that iOS version. However, if you wanted to support iOS 10 and iOS 11, this Swift runtime would still be bundled with your app binary, and it would behave the same way as described above.
Documentation on swift.org states the same:
Apps deploying back to earlier OS releases will have a copy of the Swift runtime embedded inside them. Those copies of the runtime will be ignored — essentially inert — when running on OS releases that ship with the Swift runtime.
So far so good. If you use Xcode 10.2 with Swift 5.0, and you deploy your app to older iOS releases, you will still bundle Swift 5.0 runtime with it. Then, if your app is running on iOS 12, app will use the runtime provided by the iOS, and if it's running on e.g. iOS 11, it would use the runtime that was bundled as part of the app binary. Now the first question: Is that a correct assumption?
Now we come to Swift 5.1 and iOS 13 that will be released in September. Swift 5.1 includes some additional runtime features, e.g. opaque result types, which require Swift 5.1 runtime.
In WWDC 2019 session 402 "What's New in Swift", the speaker, when discussing the Swift 5.1 feature Opaque Result Type (SE-0244), mentions that the feature will only work on new OSes:
Requires new Swift runtime support
Available on macOS Catalina, iOS 13, tvOS 13, watchOS 6 and later
This is the confusing part for me. Wouldn't Swift runtime 5.1 be shipped with your app regardless if you support older iOS versions (e.g. iOS 10 as well), thus enabling it to use these new runtime features or am I just not understanding this correctly?
\n\n现在第一个问题:这是一个正确的假设吗?
\n
对,那是正确的。
\n\n\n无论您是否支持较旧的 iOS 版本(例如 iOS 10),您的应用程序是否都会附带 Swift 运行时 5.1,从而使其能够使用这些新的运行时功能,或者我只是没有正确理解这一点?
\n
嵌入式运行时与操作系统中的运行时并不完全相同。例如,操作系统中的运行时是紧密集成的:
\n\n\nBy being in the OS, the Swift runtime libraries can be tightly integrated with other components of the OS, particularly the Objective-C runtime and Foundation framework. The OS runtime libraries can also be incorporated into the dyld shared cache so that they have minimal memory and load time overhead compared to dylibs outside the shared cache.
\n
Source: https://swift.org/blog/abi-stability-and-apple/
\nOf course, the embedded runtime cannot be tightly integrated into older systems. The embedded runtime can only support features that were already possible on the current system it is being executed. Features that require a newer systems are simply not present when your app runs on an older one.
\nNote that this has never been different for ObjC. If a class or a method only exists starting with a certain OS version, you can still deploy backwards to older system versions but then you cannot use that class/method there as it simply doesn\'t exist.
\nif (@available(iOS 13, *)) {\n // Code requiring iOS 13\n} else {\n // Alternative code for older OS versions\n}\nRun Code Online (Sandbox Code Playgroud)\nor in Swift:
\nif #available(iOS 13, *) {\n // Code requiring iOS 13\n} else {\n // Alternative code for older OS versions\n}\nRun Code Online (Sandbox Code Playgroud)\nJust like with ObjC, new Swift features will only be available for new OSes from now on. Only if it is possible to make these features also available for older OSes, regardless if these shipped a runtime or need to use the embedded one, this feature may also deploy backwards, though not necessarily all the way.
\nE.g. 10.15 introduces a new feature in its bundled runtime, then maybe this feature can also be made available for 10.14 and 10.13 using a shim library but not for 10.12 down to 10.9, then this feature will be tagged as "Requiring macOS 10.13 or newer".
\nIf you deploy to 10.15, nothing has to be done, as the runtime of 10.15 supports the feature. If you deploy to 10.14 or 10.13, then the compiler will add shim library (like it would add an embedded runtime) and on 10.13 and 10.14 the code in this library will be used while on 10.15 and later the code in the runtime will be used. If you deploy to systems earlier than 10.13, this is okay but you must not use this feature on these systems then.
\nOf course, if a new feature can be made available even trough the embedded runtime, it can certainly also be made available using a shim library for all systems that shipped with an own runtime which just didn\'t support this feature, as the shim library can then use the same code that the embedded runtime uses.
\nThe ability to sometimes make new features available even to older systems is explained by the very last question on that page:
\n\n\nIs there anything that can be done to allow runtime support for new Swift features to be backward deployed to older OSes?
\n某些类型的运行时功能可能会向后部署,可能使用在应用程序中嵌入 \xe2\x80\x9cshim\xe2\x80\x9d 运行时库等技术。然而,这并不总是可能的。成功向后部署功能的能力从根本上受到旧操作系统中附带的二进制工件的限制和现有错误的限制。核心团队将根据具体情况考虑正在审查的新提案的向后部署影响
\n
资料来源:https ://swift.org/blog/abi-stability-and-apple/
\n| 归档时间: |
|
| 查看次数: |
536 次 |
| 最近记录: |