We’re still waiting for coroutines in Swift several years in. In the meantime, we have many concurrency mechanisms to choose from. How do we know which one to choose? Let’s examine each one and compare their performances.
Swift Dependency Injection via Property Wrapper
There are so many diverse use cases for Property Wrappers, but dependency injection in particular seems like a natural fit. In this post, we’ll explore how we can leverage this newly exposed feature of the language to achieve native dependency injection in Swift.
Protocol-Oriented Themes for iOS Apps
Themes are usually downplayed as an after-thought instead of being an integral part of the development process. How many times have you inherited a codebase where the design team wants to tweak it, or business wants you to clone the app with a whole different theme. In this post, I’m going to show you the native way of theming an iOS app as intended by Apple that is often overlooked.
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.
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.
Percentage-based Spacing Using Autolayout and Storyboard
Due to the many screen sizes in the mobile world, staying relative to screen size is crucial. Hard-coding margins and sizes based on points can be short-sighted. In this post, we will subclass NSLayoutConstraint to achieve percentage-based margins.
What’s New in iOS 10 and Beyond
It is clear from this year’s WWDC that Apple envisions a new era beyond the traditional apps-in-a-grid-on-your-home-screen model. iOS 10 is more of a revolutionary iteration to the Apple ecosystem and vision. There were many initiatives uncovered that gives us clues to the future of Apple.
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.
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.
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.
Updating Query String Parameters in Swift
Adding, updating, and removing query string parameters is a common use case, but very tedious. This Swift function will help make it easy and pleasant leveraging NSURLComponents.
Multidimensional Typed Arrays in Android Resources
Android has a convenient XML-based resources architecture that allows you to define strings, booleans, colors, dimensions, ID’s, integers, integer arrays, and typed arrays. Take this one step further by storing multidimensional arrays for complex objects.
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.
Creating a Number Keypad for Apple Watch
The user interface for smart watches is vastly different than what we’re used to. We are entering a new era of UX that involves creative thinking on how we can use the ridiculously small screen real estate, while still giving the user enough power to interact with it. One thing that comes to mind is how do we enter numbers into smart watches. In this post, I would like to show you how to create a number keypad for Apple Watch.