[swift-corelibs-dev] #if __CORELIBS_FOUNDATION__
Drew Crawford
drew at sealedabstract.com
Tue Jan 5 02:08:47 CST 2016
> On Jan 4, 2016, at 3:09 PM, Tony Parker <anthony.parker at apple.com> wrote:
>
> In this particular case, how would you use the #if? Any should be source compatible with AnyObject, since Any is a superset of AnyObject, right?
Well I don't know what you mean by "compatible" but the thing about strongly typed languages is we can't do
let a: Any
foo(a: AnyObject) { /* */ }
foo(a)
because that is "type error". We can of course cast, but if in Darwin a.self is already AnyObject, casting again to AnyObject produces a warning, and I try to not have any warnings in my code.
This is kind of a side quest–there are a lot of ways to work around these problems–but the obviously straightforward one was to use #if to conditionally cast, and that wasn't available.
More broadly I find myself using the #if that I've created very often–my workflow seems to be to create an extension on an NSClass in-file that adds missing functionality and then PR it to corelibs-foundation afterwards–and conditional compilation really helps with that workflow.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20160105/a3a71560/attachment.html>
More information about the swift-corelibs-dev
mailing list