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.
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.
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.
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.
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.
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.
Let’s use the closure-based pattern to wrap CLLocationManager for allowing callers to subscribe to observables instead of using shared delegate functions.
Delegation is a simple and powerful pattern. However, closures are more Swifty and scales better. Let’s convert delegates to closures!
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.
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.
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 […]
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.
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.
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.
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 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.
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.
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.
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.
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.
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.
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.
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.
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.