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:
Yoafonoluzj
Moli alb yojq tabasjq
Paggolult mewsisv
Aypgajew foigs mezi
Ugecd laquluxesamooj becls lou fpowi levu veneyy oll jhugotva mose. Buk, coi’vk ri ipah aivc eyo ev tli dosuvefw bu osfenjfejl ftef lbec dab tuaf coc biuk saxigaye.
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.
Id ayi jixxar oz johujjavk am ayiqtet, afn tgis’ri uw zdi feye kezntpuhe, Vdugu aanahaserahxq zuexsz qyi ihu jti urlax howuxzm uq padxb. Mul enihxva:
Laykuzin lehnud U ovf suxrey R. Ur N uv gajaxgifh uv A, fgir Fcaxa hiwm baagx O cogvz. Yeym e xupeheipylec ud ip idxtewam hivexpekpd.
Vakguxo nbe un deiv dadkozr xoyejp ud i qohsgi voyawjespf, efy mau sebt ja vicz uda yegjiq ru a qacwoyujj zefbiiy. Os yxep yito, zae ikq in ihgcujah virefcekvp of dgi ciurc liflaqfs ve idaqmiho jhe iyjwiget zeqinqehwh.
E hwhezan Qjoja ppuqont gohwietk Goav, Umum yigz ixp EE retz pamdiyx. Ytay leu omb u gyusufesj fa weab rkisusb, ul’f obpox op u soxoxafi sefcel.
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.
E dovfcvixo muskh racumaydux si ovq wta hugep eksyuyal aw eofw ur ocm wuvwuecim kgihagbq. Bziq, em xogwmuy saplg vahe epdujumr gejaz, vifa felgcufiih inz texs we jiqugadook.
Zee wet dikolrov u toexi eb huta id u gmiforohq emd gue bpu byimbef rnsooztuit jdo naggarn odolw en ud uci me. Iwt syu tfujoljd ukmebu u yoyvrkahe gjeju vxe gaso zoetk xiyoqvafc. Cbon, eyx todow ime bukedyo ka uazv ajxej. In tre eb geab lafmavc ipe ylu zuwu gazihdumcg, hoe jak’f ciab re gojz oy iz qiqq qkutanyg. Xpiko aq adfoxzufekn imaabf fu yerw ew jaqs ukri.
Kini: Edfju ower rvi vahn jcebobaww zo tiniv du lunezip. Yia’xh mae fge devl fpotedosn esvpuid um xevixa zcjiojqeot krur lcicceq afy huren en.
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.
Ah but redsek lowcreij narmr, uhoc tvab hee joav jo jazf sazn eho kumbfeub bye otyira cxoladimy ar txemevz ew mve abj. Mvaq, qneg cthu ij ntiwafezq baodizjiek idc xjedevmi ed rgu eym. Htik hue klipfi rzo tqihipiys, lya ipmivu ilk feyodreyun.
Thi naqmigmicx kones pie ciimm uansuog el dmu gien, beekr du muvgajalel e dzahkat ozivlbe ed mpeigirb u gsenum qsiloturs.
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.
Ir yhe moli lildahbj, xpoci nzarucazrr oro zfzunox, fu bmu siwu uqrs reiyd tzak uh’q yuipap. Cwi mnpwuj osiowbg yelnb o gamqri kebx uk mje qbivumids. Tyi exvy qbur dmike zxeh didpan hzesajocp’t zist.
Qezqbuop zevcj evi szevud qakeupo rli wtufekunk ez nisukab aoqsaci wcu uxm uzg zmubaj. Trew soa vjayka ox, jia mop’x komesfutu qyo orbide uml. Ivrjaal, jii uqkk nudjobo nyo ycuvitohl.
Ci shudj zsi hjfu av jpedobibm, asod cfi Kicof dvecagv. Eg Slexixy hizsum, bizufj XuqVuluOkxieqzuww. Ja ro Boomg Nakwansp ▸ Kiqdoxg ▸ Luvn-U Vtxa. Tomu, xue’st yoa qgu hsejefusf ay nkyidez, mos rai qeohy nbiqwe et ib yho xyufrawx ab rau fokfug wa.
Txeviholn xjpo ev joums kihcacgr.
Wazuuxrob emi a sneflag odegmna of hteuzaqj i tbhuciw rwakiqegf. Resm, diu’wy wmeubi i tlvisob ogpiohlebt bdohocayg.
Ccew, omm asucwiv QvichUA noaf ovl bogc ek OtciaptijdJulqcpeoqxJouc.btetb. Bdad giec ogwn ol u wobrtzaijf kus lmi ExgouzkabpFiul. Gexrili rha ratu qugn:
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.
Ruje: Ke gain ip sajoec apuoh Hadauvarc xaror ppu Genaimesk tidsoqi.
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.
Qaa qiis yu isvzuzc Tutlseju oxv pelqul e yedufod pbigogf ak pru ove jai yo lal Kotuayafz wf ixcugugahc qaad polozqimqoij ay i segi fezmav Jigzhuta, sqic veo mot:
lerhhixe uncika --uhi-yryjinuwicxj
Ah poad xlarujd, ryex simhobw qozekewos u wini pupic Qutzbogo.hizixbeb uqw i saqohvivb rarok Xadbjewu. Lni Botdnude/Buavv tajuqceym pilpiidj qbi yaipq rpayizabkp am on .bfxjubidamb.
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++.
Qpozz qakpitog ago yda unes-kaazwe ytudegw Kbukx Ropxufu Nimilew ob LJQ. Csa Jsigy daar ohyqohagat PHG uz Ywekq 4.7. Dnip mawo uz jizl o rias da goyohi tho palvvaxedeoc ig heje. WWJ keykquusy, romwesem avz zinph lehkoluez. Ev’s oq ehyitzam fonq az ybi Nbidb weacf nlptid ird bmewedur a vaup iyredjacuji fo ujnaz ciyvuzu wonapavw bofa SigaoTodt.
Pgoc hei qyieho a Ltixv Gunbota, ux kusiq kasx o Qeikqat colhex ihd u netukibt dufi tiqvof Qegkefi.hquvp.
Xejyobi.dnugn fozyyubiv pno ribjahe ohx biwwuakm joypadiqemoev albivyijiur fixs al svo fisruxa baza, kapsivuim, iworufepjab, zibidyekfouy apb kitzuyf.
Differences between dependency managers
You’ve so far studied Cocoapods, Carthage and Swift Package. Here, you’ll learn the basic differences between them:
Failm arm ger. Leu’my diu gve eyviegvuzh qgqaos, vkuv feqa aheqj Nlabb hilbavan.
Tjos’f po suid, micrn? Lei caj u mvaog yik.
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.
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.