Comparative advantage of Objective-C:
- Interoperability with C++ and Objective C++
- Dynamic features like method swizzling
- Better support for writing Binary Frameworks.
Disadvantages of Objective-C:
- Since Objective-C is built on top of C, it lacks namespacing. All classes in an Objective-C application should be globally unique. So to avoid collision there is a convention of prefixing the names of classes. This is the reason we have the ‘NS’ prefix for the class in the Foundation Framework and the ‘UI’ prefix for the classes in UIKit.
- Explicit pointers.
- The ability to send a message on a nil object without crashing and the lack of strict typing lead to bugs that are hard to trace and fix.
- The language is syntactically verbose and complex, but this is expected given that it is a fairly old language.
Swift is a young language released in 2014. It is designed to be safe and performant with modern syntax and features. Swift was Open-Sourced in December 2015.
Comparative Advantages of Swift:
- Swift is safer due to static typing and the use of optionals and optional chaining.
- Support for namespaces, a clear mutability syntax, functional patterns and concise syntax.
- Interactive development using Playgrounds.
- Swift is easier to learn for new programmers, The official language guideby Apple is a great resource.
- Swift is performant and is finding its place in the server side applications. The advantages of using Swift on the server side are explained in this talkon Realm Academy by Chris Bailey, where he points out the advantage that Swift has over other frameworks on the server and the cloud. According to him Swift is highly performant and has a low memory footprint which makes it an ideal choice for Server side development.
- Swift is now stable with its ABI locked down.
- The Swift standard library code contains around 42.5% of its code in Swift. The split up of the different languages used in the standard library is as shown in this picture below. This Swift code is probably the best Swift code which developers can refer to improve their Swift coding. It is covered very well in this talk.
Comparative Disadvantages of Swift:
- Higher compile time.
- No direct way of using C++ libraries.
- Module format stability is still not achieved and is required for developers who want to share their code as a binary framework.
Swift is now officially ABI stable and can be considered to be a mature language. The future updates in Swift would not break the current code written from now on in Swift 5.
Apple offers great interoperability between Objective-C and Swift, and is not dropping support for Objective-C anytime soon. It is better for teams to start migrating parts of their Objective-C code to Swift as it is ABI Stable now.
If you are developing a binary framework I would suggest waiting for Swift to achieve Module Format Stability. Also, if you are dealing with C++ and Objective-C++ codebase or framework, then you would need a mix of Objective-C and Swift. The Objective-C part can interface directly with the C++ or Objective-C++ parts of your code and the Swift part can then use Objective-C classes to interact with the C++ or Objective-C++ code.
Confused about whether you should migrate to Swift and what not please refer to this article where it is covered in detail.
You can contact us on Twitter, Linkedin, Facebook and Github.