2 ms·
Sometime in the Swift 3 timeframe (2018? 2019?) Apple renamed all their APIs to match their new guidelines. Objective-C methods get bridged to Swift almost dire
by saagarjha 3y ago
Sometime in the Swift 3 timeframe (2018? 2019?) Apple renamed all their APIs to match their new guidelines. Objective-C methods get bridged to Swift almost directly, which means you can often call functions that were designed decades ago without it looking all that different from all your other code.
Two unrelated facts about Swift are that it has "implicit self" in that inside an instance method, you can call any other instance method without qualifying the access to indicate that it's happening on the current object. Also, it has a free function, print, that is basically its equivalent to std::cout or System.out.println or console.log in other languages. It's a common debugging technique, in particular. Perhaps you can see where this is going…
When writing apps on macOS, one makes their own custom NSWindows and NSViews. One method, -print:, invokes the system print dialog by default. This, of course, got named NSWindow.print(_:)/NSView.print(_:), which promptly made any code that tried to log a view or window from a context where those were visible suddenly start trying to literally print. Kind of amusing that the literal action of "printing", which today lives on as "printing" output to the screen, ends up meeting its roots with a name overload collision.
(If you're wondering, the function was eventually renamed to NSWindow.printWindow(_:) and NSView.printView(_:) to solve this issue.)
- miki123211 3y ago> Apple renamed all their APIs How did they prevent this change from causing a huge compatibility nightmare?
- Someone 3y agoBy not promising compatibility up-front. Swift applications were supposed to ship with their own copy of the Swift standard library up to when Swift got a stable ABI in Swift 5. IIRC, they also provided migration scripts. Certainly their Xcode tools provided hints indicating the renaming of functions.
- uranusjr 3y agoI used to mainly develop in C++ and implicit this was so frustrating. Nowadays it’s mostly Python and the explicit self is simply not an issue. (I also worked on Objective-C code at some point and that’s also fine.) Why any designer of a new language would think implicit self/this is a good idea is so beyond me.
- saagarjha 3y agoIt's convenient and mostly not an issue.