Hey iOS developer! 👋
Last week, I continued exploring iOS design patterns, with creational patterns and previously structural patterns.
So in today's issue, let’s have a look into iOS Communication patterns: Delegate, Target-Action, Notification-Center, Key-Value Observer (KVO).
Swift Delegate Protocol Pattern Tutorial
To get started with the Delegate Protocol pattern in Swift, I recommend Sean Allen’s video tutorial. His clear explanations and examples make it easy to understand how this pattern enables objects to communicate and delegate tasks effectively.
Watch on YouTube
Delegate vs Closure in iOS Development
While closures aren't typically considered a communication pattern, Naresh Kukkala's article is an excellent resource for understanding two different ways to pass data between objects. The Delegate pattern allows one object to act on behalf of another by defining protocols that outline specific responsibilities, which are then delegated to other classes. In contrast, closures are self-contained blocks of code that can be passed around to execute specific tasks.
Read on Medium
Newsletter recommendations
The iOS community is full of talented developers, and many of them run insightful newsletters and blogs. In this section, I’m excited to share recommendations for some of these great resources.
This week, I'd like to highlight the fantastic Coding with Vera newsletter by Vera Dias, where she shares insights and practical advice for iOS developers, covering everything from design patterns to productivity tips.
Target-Action Explained in Swift
The Target-Action pattern offers a straightforward way to manage user interactions in iOS. Primarily used in UIKit with controls like buttons, sliders, and views, it allows an object to respond to specific events, like a tap or a swipe. While I don’t have a specific article from the iOS community to share this time, I recommend checking out the Apple Developer documentation for an in-depth look at implementing Target-Action.
Read on Apple Developer
Bad practice: not using UIAction
Using the traditional Target-Action approach requires action implementations to be Objective-C compatible. Vincent Pradeilles demonstrates how to improve this by leveraging the addAction
method, introduced in iOS 14. Unlike Target-Action, UIAction
uses closures, offering a more modern, Swift-friendly way to handle actions without the Objective-C constraints.
Read on Swift With Vincent
In addition to the traditional Wednesday issues, I’m also sending out Monday emails featuring a series of personal articles called Monday Quick Read.
Even though there’s no new article this week, feel free to browse the archive of previous articles.
Notification Center in Swift
The Notification Center is a tool that allows objects to broadcast and receive messages without needing a direct reference to each other. It’s commonly used to respond to specific events, like data updates or settings changes. For a deep dive into this pattern, check out Begüm Ünal’s article where she explores Notification Center in detail.
Read on Medium
Key Value Observer
KVO is a mechanism that allows objects to observe changes to specific properties in other objects. It’s commonly used when one part of an app needs to respond to state changes in other parts. To learn more about this pattern, check out August Lin’s article, which explores KVO in depth.
Read on Medium
If you’ve enjoyed this article, I’d be happy if you:
Hit the Like button.
Subscribe, if you haven’t already!
Connect with me on LinkedIn.
Share the issue with colleagues or friends who might find it helpful.
Until next time!
Artjoms