Settings

Theme

8 Surprises I learnt about Swift

ristkof.be

2 points by ahigherugliness 10 years ago · 1 comment

Reader

coldtea 10 years ago

>I was surprised to find out that tuples are not AnyObjects. The reason is that AnyObject corresponds to an Objective-C object, an object that can exist in the Cocoa world. We still write apps in the Cocoa framework so mostly we deal with AnyObjects. And often times (in the case of strings for instance) there is implicit bridging between the two sorts of objects. Then there is also an Any object, which is not (necessarily) an AnyObject, but is the Swift equivalent of the Objective-C general object (represented in Swift by AnyObject). All very confusing, and inexplicably confusing if you consider that Swift had a chance to start with a clean slate.

How is that confusing, and much more "inexplicably" so?

It's clearly because Swift wanted to take advantage of its clean slate that this is the case. So you have AnyObject for items that need the legacy Objective-C object tree support, and Any for the Swift native equivalent.

Eventually this allows them to drop AnyObject, and keep Any when they're finally able to go all-Swift.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection