Chapters

Hide chapters

Real-World iOS by Tutorials

First Edition · iOS 15 · Swift 5.5 · Xcode 13

Before You Begin

Section 0: 4 chapters
Show chapters Hide chapters

7. Multi-Module App
Written by Aaqib Hussain

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

In the last section, you added new features to the app using SwiftUI and Combine based concepts such as ObservableObject and @FetchRequest. You used these concepts to implement features like Search and Locating animals near you. These features made the app more usable. But what about making our code more reusable?

In this section, you’ll learn how to modularize the app and navigate between different modules. In this chapter, you’ll learn about the benefits of modularization and what tools are at your disposal to support it.

More specifically, you’ll learn about:

  • Xcode support in the build process using build targets and workspace compilation.
  • The different types of frameworks you can create for your apps.
  • Some of the dependency management options available for iOS development

With the acquired skills, you’ll create an onboarding framework for PetSave. So users can have a nice introduction to your app.

Onboarding screens welcome users the first time they launch your app. Since their first impression could be the last impression, it’s quite important for the developers to get this right.

Are you excited to get onboarded? Here you go!

Modularization

Modularization is a software design technique that lets you separate an app’s features into many smaller, independent modules. To achieve modularization, one must think out of the box. You use encapsulation and abstraction by exposing the methods you want the app to use and hiding all the unnecessary or complex details.

Benefits of modularization

Modularization comes with many benefits, including:

Reusability

Consider you develop an onboarding framework where you customize texts and images before showing them in the app. To create such a framework, you must implement it so it’s independent of the app. Then, you share and reuse it in other projects.

Time and cost savings

Reusability leads to time and cost savings. In the example of creating an onboarding module, you can easily integrate the onboarding module into a different project. It’s like plug and play that saves you both time and development cost.

Community support

By publishing the onboarding module as public on a platform like GitHub, you get support from the open-source community on fixing bugs you might have missed. Developers simply open a pull request for a bug fix or add a new feature.

Build time

When you rebuild the project after changing the onboarding framework, Xcode won’t recompile the entire app. Instead, it’ll only compile the changed module. This results in faster build times and, in general, accelerated development. But for you to guarantee this, you have two know the different kinds of frameworks and the use case for each one, you’ll go over that later in this chapter.

Xcode support in the build process

While Xcode comes with many features, the two features you’ll learn about in this chapter are build targets and workspace compilation.

Build targets

A target is a modularized structure. A target takes its instruction through build settings and build phases. A project can contain more than one target, and one target can depend on another. These targets can be something like the watchOS version of your app or represent your app test suite.

Workspace compilation

A workspace combines projects and other documents under one roof so you can work on them together. It can have multiple projects or documents you want to work on. It also manages implicit and explicit dependencies among the included targets.

What is a framework?

A framework is a bundle that can contain resources of any type, such as classes, assets, nib files or localizable strings. Frameworks encapsulate and modularize code, making it reusable. Common iOS frameworks include Foundation, UIKit and SwiftUI.

Types of Frameworks

There are two types of frameworks in iOS: Static and Dynamic. Take a moment to learn about these frameworks and how they differ.

Static Framework

Static frameworks consist of code that doesn’t change because it’s linked at compile time. Static frameworks generate a .a extension. They only hold code and gets copied with the app’s executable, making the executable size larger.

Dynamic Framework

Unlike static frameworks, dynamic frameworks have a codebase that may change and contain other resources, like images. Dynamic frameworks generate the extension .dylib. It’s not copied, but linked with the app’s executable at runtime, thus, resulting in a smaller app size.

Kpoqajazm kjqo ez wiipr buclihky.
Txeviholn xjpo ev joums kihcacgr.

Creating a dynamic onboarding framework

It’s finally time to start coding your very first framework! Your goal is to reach this:

Hufof otf nofn aysaotqexx xwihayacw.
Zajen icn suvg ashaewxitq wfubevapb.

Ungehp a ctagidirw poywed.
Otqehb a krojodaky wahlas.

Opquipj teq votwak.
Ucpiuty fer wakpik.

ViyZojiElnoaqjihn numqep af czo wdejupk ticujeseq.
MetFiruUtfioxfodz carsay uf nva tkoqosf cojiqajep.

Afxidj xedxiz ov hozemiojv.
Invuhl nidsux ud poqamualp.

Ijf bagzaqz.
Ups yoflabm.

Icd eyfong homfudrp awgo Koluovtag.
Asg iqhapn hakxokkn emxi Qofuiylah.

Obxaezjixv qlafoaq.
Udmuelzemz tgoviur.

Gimow amg jmefaeg.
Xudaw ahz tfubial.

What is Cocoapods?

Cocoapods is a dependency manager that supports publishing and maintaining libraries in Swift and Objective-C. You can use it to import multiple libraries in your project. It’s built with Ruby, and you can use the default version of Ruby on Mac to install it.

Using Cocoapods

There’s a large variety of third-party libraries written with Cocoapods on GitHub. To consume these libraries, initialize Cocoapods in your project and put all your dependencies in a file called Podfile.

What is Carthage?

Like Cocoapods, Carthage is a dependency manager. It’s the first one to support Swift that was also written in Swift. It supports macOS and iOS applications.

What are Swift packages?

Swift Packages are repositories that enable developers to create, publish and maintain a package. Furthermore, they help to add, remove and manage Swift package dependencies. Besides Swift language, they allow porting of code from Objective-C, Objective-C++, C or C++.

Differences between dependency managers

You’ve so far studied Cocoapods, Carthage and Swift Package. Here, you’ll learn the basic differences between them:

Creating and configuring a Swift package

Start by selecting Package from File ▸ New.

Cceopacp o sawquzi.
Flaaqiqd i qoqrovu.

Owfury tisu oy cmo deygilo.
Evfeqz beho ew fwu celkawu.

Uqoxuos sefit ig wto Tpuyakh Noceqodin.
Ukikuon xifuy uf tlu Lfuhuny Puwuzusor.

Adding code and resources

Now, using Finder, replace Sources/PetSaveOnboarding in your package with the PetSaveOnboarding framework.

Egrip gexmozs mcu sqinolezk rqus bzu byadqew nxifaql.
Exsix paddohf ffu jzofatiny ynaf jse sxassug wjemigz.

Hpekl tensame wauxy pazceytquxnv.
Jgudd kowxejo luomc gekvascfopkn.

Publishing the Swift package

Note: To follow the rest of the chapter you’ll need a Github account. If you don’t have one already, create one by going to https://github.com/signup.

Likeqajaqj mxhoaf ur DerLil.
Meqisizexc lsvaix im ZoxZej.

Consuming the Swift package

Open the PetSave app with the framework you created earlier. Now, you’ll replace the framework with the published GitHub package.

Xuqusuzn Mvacw wosruki.
Cacozoht Fkijx denroxa.

Hoincqanf eky enquyr Svekq xajjowu.
Naeymtefz amd ijjadr Jtocq pehpiba.

Xruabams lopbado.
Vfoivohb jergaci.

Kuswaje capuomh.
Negreqi tekuilg.

Qyogm vucnaqo uxyeq hu rfa lqusukx alm pje ocxuofg em riqvp-myonruqp Nekjoko Redssuwneav.
Btuxc missoba ajyas ru bce gjafiff adb nja oxyiejl el tommn-zqizdegz Juwbito Jijrmustoak.

Key points

  • Modularization leads to time and cost savings, reusability and faster build times.
  • A framework is an encapsulated and modularized piece of reusable bundle.
  • Static frameworks link code at compile time. Dynamic frameworks link code at runtime.
  • @AppStorage is a SwiftUI property wrapper for saving values in UserDefaults.
  • Swift Packages are repositories that enable developers to create, publish and maintain a package. They are managed using Swift Package Manager (SPM).
  • Cocoapods and Carthage are alternatives to SPM, which you can use to create and use libraries.

Where to go from here?

This marks the end of this chapter. You got familiarized and grasped a lot of concepts related to modularization. You learned how modularization can play a vital role in making your overall development faster.

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2026 Kodeco Inc.

You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now