[swift-users] Regression in Xcode8-beta6 Swift?

David Hart david at hartbit.com
Thu Aug 25 03:27:22 CDT 2016

That proposal also says:
Deciding the fate of AnyObject lookup

We currently bestow the AnyObject existential type with the special ability to look up any @objc method dynamically, in order to ensure id-based ObjC APIs remain fluent when used in Swift. This is another special, unprincipled, nonportable feature that relies on the Objective-C runtime. If we change  id to bridge to Any, it definitely no longer makes sense to apply to AnyObject. A couple of possibilities to consider:

We could transfer the existing AnyObject behavior verbatim to Any.
We could attempt to eliminate the behavior as a language feature. An approximation of AnyObject's magic behavior can be made using operators and unapplied method references, in a way that also works for Swift types:

  /// Dynamically dispatch a method on Any.
  func => <T, V>(myself: Any, method: (T) -> V) -> V? {
    if let myself = myself as? T {
      return method(myself)
    return nil
though that's not quite the right thing for id lookup, since you want a respondsToSelector rather than isKindOfClass check.

We could narrow the scope of the behavior. Jordan has suggested allowing only property and subscript lookup off of AnyObject or Any, as a way of allowing easy navigation of property lists, one of the most common sources of id in Foundation.
If we're confident that the SDK will be sufficiently Swiftified that ids become relatively rare, maybe we could get away without a replacement at all.
What was decided concerning that? I felt sure that the lookup had been completely removed, but I’m obviously mistaken.


> On 25 Aug 2016, at 09:59, Quinn The Eskimo! via swift-users <swift-users at swift.org> wrote:
> On 25 Aug 2016, at 08:23, David Hart via swift-users <swift-users at swift.org> wrote:
>> You can’t call arbitrary functions on AnyObject anymore.
> You’re mixing up `Any` and `AnyObject`.  You can still call arbitrary methods on `AnyObject`, as Martin demonstrated, but Travis’s error message referenced `Any`.
> SE-0116 [1] means that `Any` is a lot more common these days.
> Notwithstanding the above, I don’t have any input on the change of behaviour Travis is seeing.
> Share and Enjoy
> --
> Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
> [1] <https://github.com/apple/swift-evolution/blob/master/proposals/0116-id-as-any.md>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160825/9f1fea2c/attachment.html>

More information about the swift-users mailing list