Starting an iOS project involves making a key decision: choosing the language for the development. When it comes to native mobile app development, there are two possibilities: Objective-C and Swift. What are the differences between them? What are pros and cons of each one? And, finally, which language will be better for your project?
Main characteristics and features of the languages
Objective-C is a long-standing programming language that was created by the Stepstone company in the early 1980s. It was released to the public in 1988, when Brad Cox and Tom Love published a book, “Object-Oriented Programming: An Evolutionary Approach”. In the late 1980s, Objective-C was licensed by NeXT Computer, Inc. to develop the NeXTStep frameworks and was eventually acquired by Apple. This is how it became the standard for many years in the area of iOS apps development.
Objective-C was created under the influence of two other programming languages: C and Smalltalk. This is why it has such a complicated, verbose syntax. It derives its object syntax from Smalltalk, while syntax for non-object-oriented operations is the same as in C. Objective-C uses dynamic typing and message passing. It also requires dividing classes into two code blocks: interface and implementation.
Swift is a relatively new programming language. Apple started working on Swift in 2010 and released it to the public in 2014. In 2015, Swift became open source. It abandons the Smalltalk and C heritage and has all the features that modern programming languages have: generics, optionals, type inference, and higher-order functions.
Speed of development
The features of a language can sound technical, but they have a huge impact on business aspects, primarily on the speed of development. App development in Swift is faster than in Objective-C. The usage of generics and higher-order functions results in cleaner, more reusable code. Optionals and type inference resulted in the responsibility for the code safety being transferred from the programmer to the compilator. More concise syntax and no need to create two code blocks for a class interface and implementation let programmers write fewer lines of code with the same effect as in Objective-C.
All of this makes development faster. It’s not just a theory – and while there is no official research, I can confirm this fact from my own experience and that of my iOS developer colleagues’ empirical experience.
Other pros and cons
Development in Swift is faster, but it is not the only factor you should consider when making crucial business decisions. What are the other pros and cons of these two languages?
Pros of Objective-C :
- It has existed for many years and is well tested. There are millions of lines of code written in Objective-C. There are many well-documented, third-party frameworks, and there is an answer for nearly every question.
- Good compatibility with C and C++. As Objective-C is a superset of C, and thus operating with C or C++ code works relatively smoothly.
- It’s stable. If you develop an application in Objective-C, you probably will not need to spend money on migrating the app to a new language version after a few months.
Cons of Objective-C
- It is hard to learn. Objective-C differs significantly from many other popular programming languages, and memory management is quite complicated. This is why it is easier to learn Swift by developers familiar with Objective-C than vice versa.
- Decreasing number of developers. As Objective-C is harder to learn, there are more new developers learning Swift than learning Objective-C. On the other hand, experienced developers familiar with Objective-C are usually familiar with Swift, or at least ready to learn it.
- An app developed in Objective-C could be potentially easier to hack than its Swift alternative. As Objective-C is well known and has existed for many years, it also means that reverse engineering tools are also well developed.
Pros of Swift
- Swift is safer. Because of its features – generics, optionals, and type interference – apps developed in Swift are less prone to bugs and crashes than apps developed in Objective-C.
- Apple is focused on Swift. Apple constantly develops this language and supports the community. On every WWDC there is a bunch of amazing technical talks about Swift; the premise indicating that Swift should be taken seriously.
- You will be more popular with your developer’s team :). According to a 2017 Stack Overflow Developers Survey, Swift is at the forefront of the most preferred programming languages, while Objective-C is one of the most dreaded.
Cons of Swift:
- Migrations and changes. This is probably the weakest point in app development with Swift. However, it’s already not as painful as it used to be and should definitely improve after introducing ABI stability. It used to be more problematic due to the constant changes implemented in the language. Developers needed to migrate applications to the newest versions. This costs time and money. Fortunately, with the passage of time, changes in subsequent versions of the language are getting smaller.
Kamilah Taylor and Kyle Sherman gave an impressive talk about using Swift in LinkedIn. Their conclusions were that Swift is great for small, brand new apps, however, it may not be the best solution for large projects with huge, already existing Objective-C codebases. This talk took place about two years ago. Today, Swift is more mature, and it has outgrown many of its earlier growing pains.
In most cases, developing an application in Swift is a better choice. However, I can think of two cases where you should choose Objective-C:
- An app is already written in Objective-C, and you only need to add new features. Swift is interoperable with Objective-C, which means you can use these two languages in one project successfully. However, this may not be the best option. Maintaining an app that is developed with two languages can cause problems. You must be aware that some edge cases can occur. You need a developer who is proficient in both languages. On top of that, context switching makes the work slower for the developer, because s/he needs to switch between programming languages on a daily basis.
- You need to use a C or C++ third-party framework extensively. This situation occurs relatively rarely. In such case, as Objective-C is a superset of C, it may be worth considering using this language.
When it comes to starting a new iOS project, the decision about which programming language to use is crucial. It will impact other choices, such as the architecture or used frameworks. Development in Swift is faster, safer, and more enjoyable from a developer’s perspective. On the other hand, decisions are always made in a specific context. Swift is great, but it is not a silver bullet. There are still some cases where Objective-C may be the right choice.