Now that the euphoria and dust has settled from WWDC 2019, it would be wise to take a step back and plan for the future. Here are small steps to begin your path towards the promise land of SwiftUI, Combine, and beyond.
So Swift, So Clean Architecture for iOS
The topic of iOS app architecture has evolved a long way from MVC. Unfortunately, the conversation becomes a frameworks and patterns war. The reality is: Rx is a framework; MVVM is a presentation pattern; and so on. Frameworks and patterns always come and go, but architectures are timeless. In this post, we will examine the Clean Architecture for building scalable apps in iOS.
Swifty Protocol-Oriented Dependency Injection
The key to dependency injection is protocols. From there sprouts many variations, flavours, and techniques. Although this is yet another dependency injection™ blog post, I would like to share a pure Swift, battle-tested DI implementation with no outside dependencies or magic. It combines protocol extension and type erasure to give you a solid, flexible dependency injection.
Thin AppDelegate with Pluggable Services
Many techniques have been tried to tame the AppDelegate beast, usually ending up in moving code into private functions or extensions. However, the AppDelegate is much more complex than just moving code around. In this post, let’s examine a pluggable service technique with a few bonuses at the end.
Protocol-Oriented Routing in Swift
There are hundreds of complex routing frameworks and libraries in iOS. Usually they’re overly complex to retrofit into an existing app or they completely bypass Storyboards. In this post, I’d like to offer a simple, native-like routing mechanism that leverages Storyboards like a boss to handle navigation.
Swifty Localization with Xcode Support
Localization in Xcode is handled with NSLocalizedString, but it is such a verbose and legacy-like API. There’s a Swiftier way that still respects Xcode .xliff exports and comments.
Swifty Locations with Observables
Let’s use the closure-based pattern to wrap CLLocationManager for allowing callers to subscribe to observables instead of using shared delegate functions.
Delegates to Swift Closure Pattern
Delegation is a simple and powerful pattern. However, closures are more Swifty and scales better. Let’s convert delegates to closures!
Creating Thread-Safe Arrays in Swift
Thread-safe resources in Swift can be achieved with Grand Central Dispatch. Using a concurrent queue and the barrier flag, reads can occur in parallel while writes are given mutual exclusivity for safety and optimization.
Multi-Threading with Unsafe Resources in Swift
GCD is not for thread-unsafe shared resources since it does not guarantee the same thread will be used for the queue. We can use the threads API with a bit of sugar syntax.
Full Stack iOS and WordPress in Swift
WordPress has been around for almost a decade and a half. It survived the CMS wars and remained relevant during the mobile shift. It’s been battle-tested under various scenarios and load. It showed us what a thriving 3rd party marketplace looks like. Now, WordPress is realizing a grander vision! In the release of WordPress 4.7, the REST API plugin was merged […]
Enum-based Queue Factory for GCD
Grand Central Dispatch (GCD) is a great technology provided by Apple. It provides an elegant level of abstraction to work with threads, queues, and locks. And it went through a much needed make-over in Swift 3. In this post, I would like to take this one step further using enums as a queue factory.
Common Initializer Patterns in Swift
Swift initialization rules are there for very good reasons, but sometimes it can make things tedious. In this post, I will show how to avoid duplicating code across initializers while still obey Swift initialization rules. This pattern uses static functions, tuples, and typealiasing.
Memory Leaks and Resource Management in Swift and iOS
Less code and less memory while performing the same task at hand is truly where the art comes in. In this post, I’d like to highlight some of the various pitfalls that lead to memory leaks, which inevitably result in crashes. I will also cover some tools and remedies to resolve these issues.
Swift Utility Belt Series: Introduction
Swift is a powerful and fun language. Its protocol-oriented nature allows you to do retroactive modeling and promotes composition over inheritance. In this series of posts, I will share Swift snippets that I’ve used across projects that I feel are really helpful in rapid development.
Protocol-Oriented TableView and CollectionView in Swift
Working with the UITableView and UICollectionView is verbose and inconvenient; also the API’s are inconsistent with each other. In this post, I’d like to reconcile the two API’s and add some sugar to make it more pleasant to work with these commonly used controls.
Protocol Conformance Extensions in Swift
Swift is a unique language that has some revolutionary ideas. One of which is protocol conformance extension. This concept allows you to take an existing type and force it to adopt another protocol it never knew it existed before.
Creating Cross-Platform Swift Frameworks for iOS, watchOS, and tvOS via Carthage and CocoaPods
In this post, I’d like to show you how to create a Swift framework for iOS, watchOS, and tvOS and get them distributed via Carthage and CocoaPods. It’s a technique I use to share frameworks across all my apps and with the community.
Reading values from any plist file or bundle in Swift
It is convenient to keep your settings or default values in a `.plist` file or settings bundle for your project. In this post, we will explore how to attach an extension off the NSBundle class this make it super easy to read those values.
Getting Started with Swift Class Inheritance
Swift has a unique and elegant class inheritance system. In this post, I’d like to shed light on all the inheritance goodies in Swift, such as designated, convenience, failable, automatic, and required initializers. Not only are these powerful concepts, but they also enforce safe and intentful code.
Unit Testing in Swift, Xcode, and Beyond
Unit testing has a stigma of slowing you down while you’re trying to rock some code. The truth is unit testing doesn’t have to be so dry. Once you start flipping the script, unit testing can be an opportunity for refactoring, refreshing, and finding bugs. Besides, who wouldn’t want to see a bunch of green checkmarks next to their code?: A beauty […]
Top 10 Swift-friendly CocoaPods
CocoaPods are a must for any serious iOS project. Why reinvent the wheel when the community has produced robust and feature-rich plugins? In this post, I’d like to highlight the best CocoaPods I’ve used in real-world project that are also Swift-friendly.
Creating Notifications from WatchKit in Swift
One of the limitations of WatchKit is being able to schedule notifications. This must be done in the iOS target since the notifications architecture resides in the iPhone, not the Apple Watch. In this post, I would like to show you to get around this and get WatchKit to schedule notifications on the iPhone.
Sharing Data Between Apple Watch and iPhone in Swift
There are various ways to persist data in the Apple ecosystem. They range from simple to complex. In this post, learn how easy it is to use App Groups and NSUserDefaults to share data between Apple Watch WatchKit and iPhone iOS using Swift.