Two Structural Design Patterns in Swift: Facade and Adapter

Swift tutorials by iosbrain.com My original article — “Design Patterns in Swift #3: Facade and Adapter” — was published on appcoda.com.

This tutorial is the third installment in my series on design patterns. I started with a tutorial examining two examples of patterns in the “creational” category: factory method and singleton. I then discussed two examples of patterns in the “behavioral” category: observer and memento. In this tutorial, I’ll explain two examples of patterns in the “structural” category: facade and adapter. I urge you to review my first two posts mentioned above so you can familiarize yourself with the concept of software design patterns. Beyond a brief reminder today of what constitutes a design pattern, I’m not going to regurgitate all the definitions again. All the information you need to get up to speed is in my first to tutorials, here and here.

Continue reading “Two Structural Design Patterns in Swift: Facade and Adapter”

Two Behavioral Design Patterns in Swift: Observer and Memento

My original article — “Design Patterns in Swift #2: Observer and Memento” — was published on appcoda.com.

This tutorial is the second installment in a series on design patterns started last week. There are 23 classic software development design patterns probably first identified, collected, and explained all in one place by the “Gang of Four” (“GoF”), Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides in their seminal book, “Design Patterns: Elements of Reusable Object-Oriented Software.” Today, we’ll focus on two of these patterns, “observer” and “memento,” which fall into what the GoF calls the “behavioral” category. Follow along with the Xcode projects, both on GitHub, available for observer here and memento here.

Continue reading “Two Behavioral Design Patterns in Swift: Observer and Memento”

Two Creational Design Patterns in Swift 4: Factory Method and Singleton

My original article — “Design Patterns in Swift #1: Factory Method and Singleton” — was published on appcoda.com.

There are 23 classic software development design patterns probably first identified, collected, and explained all in one place by the “Gang of Four” (“GoF”), Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides in their seminal book, “Design Patterns: Elements of Reusable Object-Oriented Software.” This tutorial focuses on two of those patterns in terms of what the GoF calls the “creational” category: “factory method” and “singleton.” Follow along with the Xcode projects both on GitHub, available for factory method here and singleton here.

Continue reading “Two Creational Design Patterns in Swift 4: Factory Method and Singleton”

iOS 11 Files app integration and the UIDocumentBrowserViewController

My original article — How to Integrate Your App with Files App in iOS 11 — was published on appcoda.com.

In this tutorial I’ll show you how to embrace iOS 11’s Files app. First, I’ll walk you through configuration of an app so that any files stored in its iOS file system-based “Documents” folder are made visible in the Files app and exposed to other apps installed on your device. Second, I’ll demonstrate how you can incorporate a Files app-like interface and functionality into your own apps. All of the Swift code I wrote to accomplish these two tasks is included below — and I’ve taken lots of screenshots regarding Files app integration. Sit back, enjoy, and learn about a fundamental paradigm shift in the iOS zeitgeist, moving from a “hide-the-details” (like hiding individual files) mindset to providing users with the ability to look at and manipulate files related to their apps using a macOS Finder-like interface, except on iOS.

To pique your interest, let’s look at a feature I encoded in the final app for this tutorial. We’ll use my app, named “Document-Based App,” to view an image file in the app’s main folder:

Continue reading “iOS 11 Files app integration and the UIDocumentBrowserViewController”

Introduction to MVVM: refactoring an MVC app using the MVVM design pattern

My original article — Introduction to MVVM: refactoring a MVC app using the MVVM design pattern — was published on appcoda.com.

[Download the Xcode 9 project from GitHub so you can follow along with my code explanation and try MVVM yourself!]

Design patterns are very important tools for iOS developers to keep in their software engineering arsenals. These patterns, along with several other best practices I’ll mention below, help developers to create reliable and maintainable apps. In other words, design patterns help in managing software complexity. In this tutorial, I’ll introduce you to the “Model-View-ViewModel” or “MVVM” design pattern. For a historical and pragmatic perspective, I’ll compare the very well-known “Model-View-Controller” or “MVC” design pattern, long favored by many iOS developers, to MVVM, which has steadily been gaining traction among the same group of developers.

In order to help you understand these design patterns, I’ll walk you through the design and coding of my app shown here:

Continue reading “Introduction to MVVM: refactoring an MVC app using the MVVM design pattern”