What I would like though would be to have this extension only apply to macOS < 10.12 and then I can name my property exactly temporaryDirectory like on newer versions. And I don't need to use my custom name anywhere.
Is there a better way of achieving this? For example a condition to include code only if !(OS >= x)
Similar question goes for full blown classes like implementing my own ISO8601DateFormatter for older systems.
The difference between #if and if #available is that the former is a compile-time check and the latter is a run-time check. If you only build your app once for all deployment targets, you need a run-time check. So no, there is not a better way to do this in today's Swift.
Heh. I did put that in there deliberately, but no, not that I know of. There's nothing incredibly technically difficult in making this work:
@dynamicallyAvailableBefore(macOS 10.12)
var temporaryDirectory: URL { … }
and having the compiler check that the signature matches up and everything before generating the code you wrote above. But it'd be a proposal that needs a lot of careful thought—how does this affect how people use framework code? What happens on new platforms? What if two people do this?