Reputation: 1818
I was doing some coding today and I created a class in Swift for one of my viewcontrollers. I forgot to tie my class to my viewcontroller so when I opened up assistant editor it gave me the generic viewcontroller base class.
And I noticed that it appears to be in Obj-C. (I've never studied Obj-C before I am just guessing based on some other code in Obj-C I've seen previously)
why does Apple use Obj-C instead of Swift. I thought Apples official language was Swift and I thought Apple did this really big push to get Obj-C developers to use Swift instead of Obj-C.
If Swift is supposed to be a better version of Obj-C and with Swift 4 we can do nearly everything in Swift that Obj-C can do why doesn't Apple just convert over to Swift and outdate Obj-C(I understand it will take time and money to do and its not just gonna happen overnight)
It seems to me that Swift would be way simpler to learn then Obj-C for beginners (i know because i learned it in like 2 months) and Swift is less complicated and better laid out then Obj-C
I know that Swift is buggy as HECK I run into bugs everyday but ill bet Obj-C was even worse when it started out (benefits of hindsight) so in a couple of years Swift will be equal or greater than Obj-C keeping its basic simplicity as well
and if i am wrong about this please correct me
Upvotes: 2
Views: 1618
Reputation: 16660
There are several core concepts in Cocoa, which are simply impossible to implement in Swift. My favorite is the responder chain. Try to do that in Swift …
Every early binding, statically typing language needs a dynamic door opener to be able to build up a framework for GUI apps. For Swift this is Objective-C. Swift without Objective-C would simply not work.
Therefore Swift has never been called the "official language". And ask some guys on the AppKit team, what they would answer.
Upvotes: 5
Reputation:
It gets down to chronology.
macOS
, formerly called OS X
(pronounced "OS Ten"), was released in 2001 after a public beta in 2000. It's API roots lie in NeXT (all those NS-prefixed classes) which began in 1985.
The heritage of what would become macOS had originated at NeXT, a company founded by Steve Jobs following his departure from Apple in 1985. There, the Unix-like NeXTSTEP operating system was developed, and then launched in 1989. The kernel of NeXTSTEP is based upon the Mach kernel, which was originally developed at Carnegie Mellon University, with additional kernel layers and low-level user space code derived from parts of BSD. Its graphical user interface was built on top of an object-oriented GUI toolkit using the Objective-C programming language.
iOS (or if you will, UIKit) was released in 2008, one year after the original iPhone.
And Swift? Version 1 was released in 2014. At this point in time I'd wager (and probably win the bet) that Apple employs more ObjC coders than Swift. I might even wager that all code in High Sierra and iOS 11 was written in ObjC.
Apple understands how slowly things should evolve. They had OS X running on Intel chips years before they announced the transition from PowerPC to Intel. They were "using" Swift in some places a few years before they announced it. It's quite possible that they are working on a Swift-based UIKit - and have been for a few years.
But commercially releasing such a monster transition? Likely years away. Particularly if you consider (1) the open-source nature of Swift, (2) it's rapidly evolving nature, and (3) the lack of an ABI - which is due out in about a year.
Upvotes: 2
Reputation: 316
That's because Objective-C came way before Swift.
Rewriting every Foundation and UIKit classes from Objective-C to Swift would take a long time and require a lot of testing just to replace something that has been in production for decades and just works.
Upvotes: 3