[swift-evolution] #available has a huge anti-pattern.

James Campbell james at supmenow.com
Thu Feb 4 02:56:47 CST 2016


So if we treat an operating and apps as a collection of libraries (I.e modules) which can be vended to various other swift modules.
How would we handle library version querying ? Is there support for this already? You are right in my polyfill library I query the version of the core foundation library (mainly due to the lack of the ability to do so with UIKit)
If we were able to query libraries (I.e modules) it would be great.
- We could query the version of the standard library of swift which you could use to know the version of swift itself- Features across platforms and versions of platforms could be queued simply by knowing if a certain module was loaded (from a library) and what version so you can handle older Apis.
Functionality that may not be implemented across platforms should be split into its own library or modules to simplify querying if that feature exists on this platform. 
If you have a class shared across platforms but one platform contains platform specific extensions to that class. Then the class would be in the shared module and you could put the extension in a separate module (I.e MyModuleAppleWatchExtensions).
You should be able to version the methods by the version of the module but only the modules by the specifications of the platform.
This way we can handle multiple platforms, be less fragile and not encourage people effectively whitelisting a bunch of operating systems in their APIs.
I think this would work reall nice with the swift PM

P.s I wanted to check do we have specifies for watch and tvos?

Sent from Outlook Mobile




On Wed, Feb 3, 2016 at 5:27 PM -0800, "Charles Srstka" <cocoadev at charlessoft.com> wrote:










On Feb 3, 2016, at 3:29 PM, James Campbell <james at supmenow.com> wrote:

We could only allow objective c methods to be queried by responds to 
But then the check is faulty, because it can find private methods.
But how do we handle Linux or any of the other platforms are you saying we need to annotate with a million OS version specifies 

If you’re checking to see whether a library contains an API or not, you probably only care about the library version rather than the OS itself.
Charles
Sent from Outlook Mobile




On Wed, Feb 3, 2016 at 1:18 PM -0800, "Charles Srstka" <cocoadev at charlessoft.com> wrote:










On Feb 3, 2016, at 3:07 PM, James Campbell via swift-evolution <swift-evolution at swift.org> wrote:

I think if we did feature detection it should ignore private methods not accessible by the code querying its accesbility. Additionally we really do need proper support across platforms.
How is that going to work, though? Most of the system APIs are in Objective-C, which has no distinction between private and public methods at runtime.
I think #available is fine as-is, especially since the compiler is able to detect if you’re using an API that’s not appropriate for the OS X version you’re specifying.
Charles











-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160204/79653ccf/attachment.html>


More information about the swift-evolution mailing list