top of page

Objective-C and Swift - My decade+ journey with iOS app development


Objective-C and Swift - My decade+ journey with iOS app development

When I first started iOS development in 2010, the introduction of the iPad sparked my interest and motivation to dive into the world of app development. Objective-C was the primary language for iOS at the time, so it was crucial to understand its fundamentals. Initially, the syntax of Objective-C, with its square brackets and message-passing paradigm, felt unfamiliar and different from what I was accustomed to in other programming languages. However, with persistence and dedication, I began to grasp its unique concepts.


Objective-C's dynamic typing system was both a blessing and a challenge. It allowed for flexibility during runtime but also required careful consideration to ensure type safety. Understanding reference counting and memory management was another significant aspect to master, as it was crucial to avoid memory leaks and crashes.


Despite these challenges, Objective-C offered some advantages. One notable advantage was its extensive runtime, which allowed for dynamic behavior, runtime introspection, and method swizzling. This flexibility enabled developers to achieve certain functionalities that were not easily achievable in other languages. Additionally, the availability of a wide range of Objective-C libraries and frameworks, such as UIKit and Core Data, provided a solid foundation for iOS app development.


The Advantages of Objective-C


As I gained more experience with Objective-C, I began to appreciate its strengths. The extensive use of square brackets for method invocation, although initially confusing, provided a clear separation between method names and arguments. This clarity made code more readable, especially when dealing with complex method signatures.


Objective-C's dynamic nature also allowed for runtime introspection, which proved useful for tasks such as serialization, deserialization, and creating flexible architectures. Moreover, method swizzling, a technique enabled by Objective-C's runtime, allowed developers to modify or extend the behavior of existing classes at runtime. This capability was particularly helpful when integrating third-party libraries or implementing custom functionality.


Additionally, the Objective-C community was thriving, with numerous online resources, tutorials, and active developer forums. This vibrant ecosystem provided valuable support and knowledge-sharing opportunities, facilitating continuous learning and growth.


The Arrival of Swift


Embracing the Change In 2014, Apple introduced Swift, a modern programming language designed to replace Objective-C. Initially, there was some hesitation among developers, including myself, about Swift's adoption. Having invested considerable time in learning Objective-C, I wondered if transitioning to a new language would be worth the effort.


However, Swift's advantages quickly became apparent. Its concise syntax, built-in error handling, and type inference made code more expressive and readable. Swift's type safety features, including optionals and value types, reduced the likelihood of runtime crashes and enhanced overall stability.


During early Objective-C days one of the main challenges was the management of memory allocation. With the introduction of Automatic Reference Counting (ARC), it became much simpler and less prone to memory issues. ARC automated the process of deallocating unused objects, eliminating the need for manual memory management and reducing the risk of memory leaks and crashes. This shift reduced the cognitive burden associated with memory management in early days of Objective-C. And with Swift this burden got significantly alleviated.


Swift also introduced new language features such as generics, closures, and pattern matching, which enhanced code expressiveness and facilitated the implementation of modern programming paradigms, such as functional programming. These additions empowered developers to write cleaner, more maintainable code and allowed for better code reuse.


SwiftUI


A Paradigm Shift in iOS Development In 2019, Apple introduced SwiftUI, a declarative UI framework that marked a paradigm shift in iOS development. SwiftUI offered a radically different approach to building user interfaces, leveraging a reactive programming model and a live preview environment.


SwiftUI's declarative syntax allowed developers to define user interfaces as a series of state-driven views. The framework took care of managing the UI's state changes, automatically updating the views when the underlying data changed. This reactive nature eliminated the need for manual UI updates, making the code more concise and less prone to bugs.


Another significant advantage of SwiftUI was its live preview capabilities. Developers could see the changes they made to the UI in real-time, without needing to compile and run the app on a simulator or device. This instant feedback greatly accelerated the development process, allowing for rapid prototyping and iterative design.


Furthermore, SwiftUI's data binding and state management mechanisms simplified the handling of UI state. By leveraging the @State and @Binding property wrappers, developers could easily manage mutable state within the UI hierarchy, ensuring consistent and synchronized updates.


Embracing SwiftUI in Existing Projects


When SwiftUI was initially introduced, it was not yet mature enough to replace the entire UIKit ecosystem. Therefore, migrating existing projects from UIKit to SwiftUI required careful consideration and a pragmatic approach.


In my experience, I chose to adopt SwiftUI incrementally, starting with new features or screens while maintaining the existing UIKit codebase. This hybrid approach allowed me to leverage the power of SwiftUI gradually and mitigate any risks associated with migrating the entire project at once. It also provided an opportunity to evaluate SwiftUI's capabilities and assess its compatibility with existing functionality.


By embracing SwiftUI selectively, I could benefit from its strengths, such as its declarative syntax and reactive programming model, while still utilizing the well-established UIKit framework for certain complex or specialized components. As SwiftUI continued to evolve with each new iOS release, the compatibility gap between the two frameworks narrowed, enabling more extensive adoption of SwiftUI in existing projects.


And my journey continues


My journey from Objective-C to Swift and SwiftUI has been an exciting and transformative experience. While Objective-C laid the foundation for my iOS development career and provided invaluable knowledge of iOS frameworks, Swift and SwiftUI have revolutionized the way I approach app development.


Swift's modern syntax, safety features, and enhanced memory management have made code more robust and easier to maintain. The introduction of Swift enabled me to embrace modern programming paradigms and take advantage of powerful language features.


SwiftUI, with its declarative syntax, reactive programming model, and live preview capabilities, has changed the way I design and develop user interfaces. The shift from UIKit to SwiftUI has streamlined the development process, accelerated prototyping, and facilitated code reuse.


As iOS development continues to evolve, it is crucial to embrace new technologies and adapt to change. The experience of working with Objective-C and Swift expanded my skill set, and enabled me to architect and build Finotes, a lightweight framework that detects bugs and performance issues in mobile apps.

Blog for Mobile App Developers, Testers and App Owners

 

This blog is from Finotes Team. Finotes is a lightweight mobile APM and bug detection tool for iOS and Android apps.

In this blog we talk about iOS and Android app development technologies, languages and frameworks like Java, Kotlin, Swift, Objective-C, Dart and Flutter that are used to build mobile apps. Read articles from Finotes team about good programming and software engineering practices, testing and QA practices, performance issues and bugs, concepts and techniques. 

bottom of page