Slide 1

Slide 1 text

Mani Ramezan May 2024 Enhancing Swift Development through Modularization and Automation

Slide 2

Slide 2 text

About me • M a ni (M a a ni) R a mez a n • St aff Engineer a t LinkedIn • Kodeco • Tech editor • Discord iOS moder a tor • Previous bootc a mp mentor

Slide 3

Slide 3 text

Agenda • Modul a riz a tion in Swift • Autom a tion tooling • Gener a l tips a nd tricks • Q&A

Slide 4

Slide 4 text

Modularization in Swift What’s a module in Swift “A module is a single unit of code distribution — a framework or application that’s built and shipped as a single unit and that can be imported by another module with Swift’s import keyword.” Swift Docs

Slide 5

Slide 5 text

Modularization in Swift Bene fi ts of modularization • Provides n a mesp a cing • Encour a ge implementing code th a t’s: • Reus a ble • Sc a l a ble • M a int a in a ble

Slide 6

Slide 6 text

Modularization in Swift Faster build • Better resource utiliz a tion • Build multiple modules simult a neously • Single module • Module c a ching • E a sier to scope the e ff ect of ch a nges • Help compiler to help you App M1 M2 App M3 M4

Slide 7

Slide 7 text

Modularization in Swift Look out for • Mixing Objc a nd Swift code together • C a n result in overly complic a ted dependency gr a ph • Alw a ys pro f ile the build • Be c a utious a bout a dding new dependencies between modules

Slide 8

Slide 8 text

Automation tooling Why automate? • Cre a te a Xcode project • Add the project to worksp a ce • Build settings • Bundle identi f ier • Codesigning • Min deployment • Compiler f l a gs

Slide 9

Slide 9 text

Automation tooling Tooling • coco a pods/xcodeproj • Written in ruby • Used by coco a pods • H a s gre a t document a tion • tuist/xcodeproj • Written in Swift • Used by B a zel

Slide 10

Slide 10 text

Automation tooling Xcode project structure • xcworksp a ce • xcodeproj • T a rget • xccon f ig • Source f ile • Resources • …

Slide 11

Slide 11 text

Automation tooling xcworkspace MyWorkspace.xcworkspace ├ xcshareddata │├ IDEWorkspaceChecks.plist -> General workplace checks and settings ├ xcuserdata -> Used by Xcode to store user states ├ contents.xcworkspacedata -> Includes references to xcodeproj fi les

Slide 12

Slide 12 text

Automation tooling xcodeproj MyAwesomeApp.xcodeproj ├ xcshareddata │├ xcschemes ├ xcuserdata -> User speci fi c con fi gs used by Xcode ├ project.pbxproj • Where most of your automation work is done • No o ff i cial documentation • Each item is assigned a unique identi fi er • ASCII/NeXTSTEP Property List

Slide 13

Slide 13 text

Automation tooling Build con fi guration • C a n sh a re Build Settings by using con f igur a tion f iles • Multiple con f igur a tions c a n be combined together • #include “Sh a red.xccon f igs

Slide 14

Slide 14 text

Automation tooling Set based con fi guration

Slide 15

Slide 15 text

Automation tooling Tip on reading each con fi g docs • a lt+double click a ny item in Build Setting to bring up the document a tion a nd the environment v a ri a ble n a me for th a t setting

Slide 16

Slide 16 text

Automation tooling Automated steps • Cre a te a new xcodeproj • Add m a in t a rget a nd unit test t a rgets • Add con f igur a tion • Add def a ult f iles like unit test a nd umbrell a he a der • Upd a te your m a in pbxproj f ile to a dd this new fr a mework a s a dependency

Slide 17

Slide 17 text

General tips and tricks • Alw a ys cre a te a b a se xccon f ig f ile • T a ke a dv a nt a ge of con f igur a tion hier a rchy • If possible, move to y a ml structure a nd use XcodeGen or tools like B a zel to gener a te projects • No more merge con f lict on pbxproj • Modul a rized unit a nd UI tests a s well • Cre a te unit a nd UI test util fr a meworks

Slide 18

Slide 18 text

General tips and tricks

Slide 19

Slide 19 text

General tips and tricks

Slide 20

Slide 20 text

Q&A [email protected] Kodeco Discord Chat