Swift vs Objective C
August 15 2019 0 Comment

Objective C vs Swift
Objective C & Swift are the languages used by apple for mobile app development or iOS app development
Objective C was created as an extension of C in 1984 by Brad Cox and Tom Love.
Advantage of Objective-C:
1. Objective C is interoperable with C++ and Objective C++.
2. Objective C is rich with dynamic features like method swizzling.
3. Writing Binary Frameworks are more better in Objective C.
Disadvantages of Objective-C:
1. 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 FoundationFramework and the ‘UI’ prefix for the classes in UIKit.
2. Explicit pointers.
3. 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.
4. 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.

Advantages of Swift:
1. Swift is safer due to static typing and the use of optionals and optional chaining.
2. Support for namespaces, a clear mutability syntax, functional patterns and concise syntax.
3. Interactive development using Playgrounds.
4. Swift is easier to learn for new programmers, The official language guide by Apple is a great resource.
5. 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 talk on 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.
6. Swift is now stable with its ABI locked down.
7. 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.

Disadvantages of Swift:
1. Higher compile time.
2. No direct way of using C++ libraries.
3. Module format stability is still not achieved and is required for developers who want to share their code as a binary framework.
Conclusion
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.