Slightly OT, but when might one choose to write part of a new app in Objective-C instead of Swift? From my understanding, Swift can call any ObjC code.
Slightly OT, but when might one choose to write part of a new app in Objective-C instead of Swift? From my understanding, Swift can call any ObjC code.
For example, this the AppKit API for pulling a URL off of the pasteboard:
+[NSURL URLFromPasteboard:]
It's easy to find, since it has both URL and Pasteboard in the name.The Swift version gets melted down to this:
URL(from:)
which is obfuscated nonsense. Unless you already know that API exists, you'll never find it.The Swift version of AppKit is littered with this kind of obfuscation. Since I don't code in AppKit very regularly, I usually just throw my hands up and switch to Obj-C whenever I start running into these kinds of road blocks.
The Obj-C naming convention has advantages and disadvantages, but has always been considered verbose. The Swift designers considered this a problem in need of a solution. As is almost always the case in software development and language design, the solution was a giant overreaction and overcorrection that just replaced one problem with another.
The Swift API is
init?(from pasteBoard: NSPasteboard)
Which should autocomplete/hint while writing code. The documentation is in the type, not littered within the function name. Much more easier to read and write. The "pasteboard" is still very much in the function declaration.Compared to the obj-C version:
+ (NSURL *)URLFromPasteboard:(NSPasteboard *)pasteBoard;
Not sure why they insist on no spacing, or sane formatting, for Obj-c. I still can't read most Obj-c - it's horribly designed.It does not. Parameter types and alternate parameter names are ignored by Xcode autocomplete.
If you want to use init(from:), you have to already know that it exists and does something good. Typically, you only find a method like that by looking at the Obj-C header. And that method is declared in the NSPasteboard header, not NSURL.
Or is it impossible to write a good auto-completer for Swift because Swift is rather unique in splitting function names into multiple strings?
IIRC, Xcode uses LSP; is that a bottle-neck?
That is something I wouldn't have thought I'd hear one day ;-)
I also occasionally need to use C++, which ObjC makes easy in the form of Objective-C++. Swift doesn’t (yet?) have any ability to interface with C++.