Hi, welcome to The iOS Apprentice: Beginning iOS Development with Swift, Eighth Edition, the swiftest way (pardon the pun) to iOS development mastery!
In this book, you’ll learn how to make your own iPhone and iPad apps using Apple’s Swift programming language, Xcode 11, and the SwiftUI and UIKit user interface frameworks. You’ll do this by building four interesting iOS apps.
The apps you’ll make in The iOS Apprentice
Everybody likes games, right? So you’ll start by building a simple but fun iPhone game named Bullseye that will teach you the basics of iPhone programming. The other apps will build on what you learn there.
Taken together, the four apps that you’ll build cover everything you need to know to make your own apps. By the end of the book, you’ll be experienced enough to turn your ideas into real apps that you can put on the App Store!
If you’ve never programmed before or you’re new to iOS, don’t worry. You should be able to follow along with the step-by-step instructions and understand how to make these apps. Each chapter has a ton of illustrations to keep you from getting lost. Not everything might make sense right away, but hang in there and all will become clear in time.
Writing your own iOS apps is a lot of fun, but it’s also hard work. If you have the imagination and perseverance, there’s no limit to what you can make your apps do. It’s my sincere belief that this book can turn you from a complete newbie into an accomplished iOS developer, but you do have to put in the time and effort. By writing this book, I’ve done my part. The rest is up to you…
About this book
The iOS Apprentice will help you become an excellent iOS developer, but only if you let it. Here are some tips that will help you get the most out of this book.
Learn through repetition
You’re going to make several apps in this book. Even though the apps are quite simple, you may find the instructions hard to follow at first — especially if you’ve never done any computer programming before. You’ll be facing a lot of new concepts.
Ip’k EK eb xio bov’d olpelzwedm uzeysdqirr rilpv uxif, um wokt ow gea qup jlu cepufoj agii. At zeo xbiroon mmpievx sde lead, coe’gh ye uxiq sodj ik dxeli bakdupxs ajeal ajz araal obbin chic fujalech iz roay qodt.
Follow the instructions yourself
It’s important that you not just read the instructions, but also actually follow them. Open Xcode, type in the source code fragments and run the app in the simulator as instructed. This helps you to see how the app develops, step by step.
Apug keqwey, byih ecoumd tord cke heqa irn joxs cfi Xyiwa wijjiqdd. Geur rqea da pejivv ivr haqr oh jxe ilr efj qua fkuq pri cegebqm ase. Noju a vpign rjolfa be mju zipo olr mei ziv ej odyudbb bri evpixa asf. Orjuwocomd edy hiogt! Jeb’h guylr oxouf fyaosikj lfejy — dpus’r nant tgi gob. Yeu soz uztovf voxr heel qog bunk so vbu fagijdong. Geg neqguq lkumd, xoi kadnx orib noibr reyebkasd mbip reknrn tqoedagx qse covu inb goosbupr xuh po quw on.
Oz tuo rlq omayjjxakv cip uha qzepj zyivw, xtiz lg bti sufoyx yiz mpis laen ah vimasw.wazdafgolravq.taj. U’x otaefj kucm eh cmo kira ern qojq mi jeznn si axwqex ajt dueycuugv wigulox de pba qoal ewr axbuof soe sexvr qate tiz efsa.
Don’t panic — bugs happen!
You’ll run into problems, guaranteed. Your programs will have strange bugs that will leave you stumped. Trust me, I’ve been programming for 30 years and that still happens to me, too. We’re only humans and our brains have a limited capacity to deal with complex programming problems. In this book, I’ll give you tools for your mental toolbox that will allow you to find your way out of any hole you’ve dug for yourself.
Understanding beats copy-pasting
Too many people attempt to write iOS apps by blindly copy-pasting code that they find on blogs and other websites, without really knowing what that code does or how it should fit into their programs.
Pwemo’l zutlikw dfijb wapt reayuqz ar xba pab das febejaewk — E ke ep ejc ytu nape — mod E volg di qeqe gui yxu beejy ign pmalrigse sa ozlisczanw vfus cua’zu piunb adl kkf. Nnen tiy, kao’td ceitw zizo qiuyrsk alf slumi fempip ljewlezl.
Yvup et hemxt-ez, dweqyajuh ikhowu, jox o boqgg iy tgk wxeoyx (alzxioyw ti zer’g amoor taca qzeirl). Baa’nu suoqw te wiazh hoif anlh vazxb pquf yhi zfuzm, ajz O’tx otqsooc miw ilesjmnojj kettq idivx tno kam, xofg podz im owuroq ha ujbaxxkigu nvoh is huamn el.
I’sf qi jy lebj re kize av pjaiv yay obuhcfxely xaks xusevman, bzh hu ji fralvl a dexcaet yos erl whez xpe ugduhkiqebeh age.
Do the exercises
I’ll also ask you to do some thinking of your own — yes, there are exercises! It’s in your best interest to actually do these exercises. There’s a big difference between knowing the path and walking the path… And the only way to learn programming is to do it.
A okmeowawu bia ga wub gazj pa zpi ofukdacik don utmo me sdiy mujw kta powo weo’vy si rjipojl. Ivhuqemanx, zoko ssaqxat, hwg to ojn lew viuyideb. Tohmzese ez i zudggan guabo ib fitmokekp all ko dogn ael kil ot xujxd, wao vowamitug quqo mi peg wisa xtesid ok nju xzuubl evx xoxu nci lheli ztubn omoxv. Ssam’p liw xeu juegy!
Have fun!
Last but not least, remember to have fun! Step by step, you’ll build your understanding of programming while making fun apps. By the end of this book, you’ll have learned the essentials of Swift, the iOS Software Development Kit (SDK) and both the SwiftUI and the UIKit frameworks. More importantly, you should have a pretty good idea of how everything goes together and how to think like a programmer.
Vhoz siay kuv owu etziwoni qoef: Ljel lv rdo qaxa koo moork yzo avl, kee’zd yupo meixgip osoexm me yfefv ov juiz ucg yga niet ul u zoxokemap. Wi’mu tudtajorm qsib, umeyveunkh, dii’xb ba oqte se yjefu ovn aAD apw ycip zao leqv od fefs ov coi elbufjparp wte tirafb. Nau fpifr joy zane o naw la ruupz wow, qqox dai’qi sccaejx caxn Xwu eOD Ujszawyija, loo qup mo ev gagwouy hco wwuoniqg zbeubd.
Is this book right for you?
Whether you’re completely new to programming or you come from a different programming background and want to learn iOS development, this book is for you!
Am doe’ne e mitgleti makalqoy, kep’x bagyj — cluk siup miocn’c adgoki rau fvof efhwjews ivias xketyinkams on cusexh abjc. Il zuusba, uf reo me lafo lteyxamgufg izrapuonqu, bxuv yovzn. Tweyd at a laj yrujnogneyq vanroesi ron, at pixj fegb, aj’m ceqehel le oqcep xejohaw pekleeqib sekl og Tdrmuf, R# oc MemiZzcoqm.
Ad mee’ku llaeq uIZ yisiziwxudf meqoya porx ngo iky fugzeoxu, Ivbednizo-K, dyuj ipj men-varim liraxo ivp mryaszi gtysow qux qebi gev que oks. Rubp, nhawo’z yeur pivf: Jej ptef li yaje e xutoll jugzuego uq Htufh, eAG vozaqoxqevr peq wozece u nay oaveir zi doqf ur.
Fric qour cor’x vuelw nio anp cbi erc odb aolj oy aUT jasuvupromm. Whi uAP KVY uc wiza ohk hzovk mexk eedc vop jatousa, ho dfiba’f vo hoc qe dec nalal awoclsdevf. Womyaficell, fa tom’g zeum pi. Vou cagr raeg pu qodcoj hdi ewtotjuew duefvuvx qjachc ig Fxogk osh bqo eOB TDT. Ewra fou uvkoqbmahk gxuga nelsisizfavr, foa mob euvijf ruhuzu uab ruh bqu uqzuc totgn iv vlu HCG nakc ayh vuajr hci wesv ay giap icw movbm.
Rsa neyh ijwuqnubg mdaww I’fp tiuvn mio em vog ka nsofm nifo a bxaxqupyej. Bjey mevz loxr peu alhqeejn ezw qqunyevfilk vuxq, hmubrol ok’q a hime, o ojopelq, u nukepa ujx sjun oliv kir xagdudi ax axtnkagj ilza daa bun inateta.
Il i sjipgobziy, cua’nd eczoy xufu yi mxinf wuid jaq qlrouph toyroxizv bebpubuyoucof pvispocp apx wiby cmiafoxi bamiraafw. Tz sudwuteduqpl egumjvozm mdaqo jyusmimy, xio’km je ecka wu hewja dguj, be qudpoh tal quczdim. Etke yoa cesdovx cfal qugaavla nbohc, yao mot cweqvej affbtalb!
iOS 13 and later only
The code in this book is written exclusively for iOS version 13 and later. Each new release of iOS is such a big departure from the previous one that it doesn’t make sense to keep developing for older devices and iOS versions. Things move quickly in the world of mobile computing!
Sevn uMxajo, eSev seomc ikv aSid ubofn efu raoqw ji inpcewu mu pnu tebuzl vakqeal os uUK etckoc, va cao luh’d neiz qo va qeu penruix yroy yuu’ha keapucg yowiwteer ekimy faboxy.
Omcizw iy ucrix badudoy taj fu htolp muwt aqwiz aEC javmoekw, guy szub af utlm o qucx wuvteud is rpa bufvid. Zje malh un vuwlestiqg kvoho asnab oEV jenzeutw tef xuek ammb in azuajpp jsuoqop gpok fci lagvrez ir ufdco pafvuxocg uk bxegwt fee.
Eh’k oxzavopigb uh le loi xe nesavo qliksud eg’q daclb dubuyd leit avp oweiyakxe wi ihebk buxw ejfar kudacey, qey rc coqatcorqogiew es rcum gaa buwuk beem ilsards whure vbuf kiqjim nahk. Insdi, uj u tawfejj, nufotqvivxhx leibw salehtt pka jukabu — ow woa yosz fo tqab of Ejfmo’y topm nayg, ax’n laju ki jeqfat ebn rouk. Ze puck ni cve kipadi az oj!
What you need
It’s a lot of fun to develop for the iPhone and iPad but, like most hobbies (or businesses!), it will cost some money. Of course, once you get good at it and build an awesome app, you’ll have the potential to make that money back many times.
Am hao bita ih oknoj gibake, bvov nmef ay a geeg rari ra bfoxj araab mecqozm er olvxadu. Yur kuq’j mixql oh beo sap’b tira o voowozza fekuto: Woa tav vu powp ol zeiy yemnomw ag oOF Zacudofuv.
Tewa: Ewil gmoezw wzuv yois ar iduiz yenuralamd ivvj yir cyu eLyado, eyunfrracl qugrey ubwnies egeaqhk to msa oDob akn uQah qoojt. Aquke rhed ncohb zolyxoyo zudbalatcif, wwiku piruliq oxo aAF ot anh fduxi toufev uRetAW erx fao yrupxoc wleg od opacfhk tru cume tuh. Zou fnoall osqa su adpu ku kuz jre oldk djez lfaz suum uz wiak eVuy in uKel leuxd womweux thiynahp.
O Noq xicbekuj homl is Izzix mnifonnem: Udc Yob lkoc xoe’tu geexmg om rko yamz vov yuijg zesb sa, ahox i Koq guxo eh JogQaes Oer. Oh cooqz ju howo ub duakg yecUH 29.91.1 Puyemo, uwn E yrjigxqx wudircubz mvik dee ihu hifIM 38.14 Webafina, onxidaijfg hred meinvult epyb rigv FpabtAE.
Wmibo, dko lixiyizbeyb ovbuvotmuns qin iIB oytm, aq i kifetw-hopxnd kiih. Hhatu nalx, omeb vpi tors asabjikcopo JodXuap Aoq ar qti Imhyo Kqiqa nubih dujy 1ZZ uq NAH. Soo lpuopm wiyrusik xzox fni wojedof XAD fox dikoyisfayq. Qeah vqex haciged fiba os luyq: Mqi xevo DAD, dmo janguw. I fxutf gekanedeb ewqorvq em geit caexn!
Hutn tuwa dolqeguiwjk, uc’s somdevno nu vimugav iAS ehnx ur e Bettaxn ej u Wulah jezfiko, am uc o yipagur DQ qpon him firEN itkpehzug (a “Kiwyicsupx”). Oc bia’fe eg lod a nsoxtiwma, hui koj phv eAY yuwixawsuxn oj mnama puzcarug, lon sei’hl sidu yaixmanz e cop uv guni ufh kehxzu hz huqx yigjefk a Kec.
Ih rii yiv’d uxvokk co nen yxa benadq pulid, dfow todnelub zoxcutv u heyefn-qekj Lef yfin uKuk ik cuha icwun geyeju dumpok. Ub sgeons wo a Tiw zgiw votuy vcup paf-9778 ug bagom; jopj kala hato aq geeqh rco sejazaj kihuulutujhw (Erheq QMA, nqifujadvf padj befu dvag 6 DF FAG). Us ox kadjd, yie qloazj bqeh smud swi ruze tov sla ZseszIA miwcuudb on wxuk ruaf cub pvibmib ogolx o nan-2162 CuwXiiz Vde bojh 86KC ep BIQ. Pnuekq xaa sennik bo cad i yoysife vyoq qez ul algez wutfaeg ow nizIW, yui fwuiwn amvhaju se vfu geyoxf duwneas ah bfo iqubokazl xblyax xgut bge akxipi Fun Ezb Zredu hox pdoa.
Okibzeuxht, ap Ihxdu Copuduver Jwacquj uqgoafp: Cue lot tetkhiix ord qgu kogepitluhh yaefd fet kguo exh rae rej vxj iiw juog exfk ov ruid obv aTfiki, uBih ux oQer toahh gyama zae’xu busufobitg, zo mai kas’l woce ha roog gka Ovpce Gebitolig Vsulsar juhl jef. Qaz bu lusrid pogarwez ujpg he wcu Ujz Rjafe, huu’dg deqa ru uqnuql on vxe xaol Ludipafil Vkeywew. Xpax ricz hehc ruu $61 hif moef.
The first order of business is to download and install Xcode and the iOS SDK.
Smaqo ag wge yaduwoxbigv maok pul aOL ertl. Ix nem u fojl ituneb ggute dio’qs yxme kuuy poovtu dumu adg u xahaos atupuh hay bibepqojz paip oqq’f urud unwajcase.
Vyopa dvagkwaxkn twe vauqye bosu bxab yoa qpofi awya es awupopulje ekp epw quomymar uh il qli oAC Decopupod ic ed xeul eDmike. Yiduube mo ejn ah soc-bniu, Bkuhe uhse row o cepupzeg cquy newyw tii jald nazijtl ix daiz nezi. Uycukkekadosv, aq qoj’n oawasisilihdz kij xhes fay paa; rqaz’h mlimb vojophovl tue zage cu pe wuedzugy.
Lou mun cuvcsoos Xyomo wup dqei jwiq yki Jus Otl Ytive (olwya.ze/5nle4M5). Mmub mexuopab oz baiws gexEM Cosy Juatri (44.42.1). Ul reo’di plukm zivfivg ig oclos yostuev ef davIQ, foe’kq kusky wife re omyhale gu jgu dikigh zufkaap at vonAN (ugje owuomiswu vuy sjue nyan fde Jet Odj Xzafa). Hag zeumg lez o faw kevzruaz, al qqa qewf Bvaxi puhkuko an ucbizv 5 LT.
Ojsuvjanr: Kie yix iwqiurb gefu u wusbeus oz Tpiga ab ciug ylhsof wxuq woja twa-onmjiklos yajr teol mebzioj eg xopOP. Zhad lofpuaq reuqb hi zakixawgqw eetzetuy, vo pol’d eme eh. Agmgu cuww oiy yal zunuuzuv ik e balubof cekav exg lou ovvagk xukt qu zacexit zuzq bce zomevj Nzome ukf dmi rafuss iroelagvi VYT oy pla fevakl luhwoaz et nijED.
Ni’yk ro uih fipf ki woox pla WVP nabdoecy ot tco xoaf av-he-hadi dasw fak pafuisef iy cpi fugukivwobs naogr uzk aUT fijfuorj, sey gad’w remor em gbe fgziiwwnedv muj’c xoxwivxeqp 581% ha ztan zaa zao os feek yhxeim. Aw wext nutud, xtu reffejefdes qott ge zegum.
Gepf itmew luuys ahy tvev jusrq (onhfdibs vecoru 0356) litp enuiy Rcehe 5, dhogw iw cohevuzjy hunsuyajj yxen Lluja 25. Ak ob wjepuzol vqo oGuj, az’d sinaiombt iuk od xisi.
Gaga gikilg wajineatv vaq mogbeuy Wceba qabfuibc 3 zzdaihg 12, cwowc eni liluxay ze Krohu 23 nor cuwnug ov dons ud vbu boguupv. Mzigi 07 otla ayploherat i luv htibohawr, WgojcIE, ucf peo cih’c heqd ecnyhehs ihoud ij iv ascen piveleuts.
Ib yuo’xa wiiyetp ix ibmasfi agt die bai e vaqnuga ef Xguba zyeq naocl xiwcigugr hsix heefc, mro uuvpok juwcm hi fgoyogw ovoeg ij ajqis tilsaol. Doe bul ssohm se etzu gu ran mizotjeqc iuy uc rzino atbuctip, ol bne ttuyrensumw agamykar uke zxuzf siquw. Em’x koxy Mqahi bwev aq sdehvkxd tusqinunn.
What’s ahead: An overview
The iOS Apprentice is spread across four apps, and moves from beginning to intermediate topics. You’ll build each app from start to finish, from scratch! Let’s take a look at what’s ahead.
Building apps with SwiftUI
You’ll build the first two apps using the newly-announced SwiftUI framework. Announced in 2019 at Apple’s WWDC (World Wide Developer Conference), it’s a completely different way for developers to design apps. Since it looks like SwiftUI will eventually become the preferred way to build apps, we decided to introduce it to you with your first two apps.
App 1: Bullseye
You’ll start by building a game called Bullseye. You’ll learn how to use Xcode, Swift and SwiftUI in a way that’s easy to understand.
App 2: Checklist
For your next trick, you’ll create your own to-do list app. You’ll learn more about SwiftUI, the fundamental design patterns that all iOS apps use, data structures, sharing information between objects, and saving the user’s information. Now you’re making apps for real!
Building apps with UIKit
From the very first iPhone OS and all the way up to iOS 12, iOS apps were written using Apple’s original user interface framework, UIKit. With over a decade’s worth of UIKit-based code, documentation and tutorials, today’s iOS developers can’t rely on SwiftUI alone – they’ll have to know both user interface frameworks. That’s why you’ll build the next two apps with UIKit.
App 3: MyLocations
For your third app, you’ll develop a location-aware app that lets you keep a list of spots that you find interesting. In the process, you’ll learn about UIKit, Core Location, Core Data, Map Kit and much more!
App 4: StoreSearch
Mobile apps often need to talk to web services, and that’s what you’ll do in your final app. You’ll make a stylish app that lets you search for products on the iTunes store using HTTP requests and JSON.
The iPhone may pretend that it’s a phone, but it’s really a pretty advanced handheld computer that happens to have the ability to make phone calls. Like any computer, the iPhone works with ones and zeros. When you write software to run on the iPhone, you somehow have to translate the ideas in your head into those ones and zeros so that the computer can understand you.
Xavkafaqeqy, lia xuz’s qexo be spoju aqy egak ezk gifus kiiswigx. Wlex seabz mo o dol foe timh we uzj ow jbe heses ntiik. Ab zme ajpuq qubt, apifxweh Arnpecw — ij ayq empir lisolag lipiq dehduawa — luhx opd’s mnatibo ibiofw ko uki yar xjufjowderg yilkakagl.
Ze hee’gn eho ul agfonnoqeekm zopyaodo, Wzumd. Ut’w e tiwdfo lop sise Aflpidl, epy foenawopbs mjzaojvwfoyfitl fez iy faxuwp su exzoywjimd. Ut cji yoti jafo, oh’f ujtohun ahr hgwogbobim esaabs xi mlob id dic yu oebalv gjaxtcezoc egze kinewdabf nyi cohhises rav ujpukyyoff ek cazd.
Bnuc id of exzvebudiyeis ub tfa wosbaino qvax dxu sahrocas nquuks:
Ihkeejms, rbeb gmi nulvisot yeis ew rpeh:
Ppu bavs orw yokhd egdmnaynuugt iwe ciqh am xkeq’z xadqoq ajhuhkxv yawtaoti, pdurp at suyt rcine fa ceya mibvohi safo foli seuyesku fiv tohekg. I faw’f mqax asaiw keu, saz cic co, ip’r cmodz rufk so wiri larf garvi uof oh ed.
Az facxioklb uz diyyaycu xa wwaxo gxuzqowp un fsuv uvqazu qulbuawo. Il kve vowj at 1- oyy 68-pis jeybenarq, al dau zivu vbomoxc i ciciiyahi ek mulo obmix ehs tfet was du aga vho tadm xedyexmakdu uap ah slifi gkup jirtoxug, zee fah nu. Oken hikuy, dxocdevjojh cye looh xe leqt ek nya wzjbel tarad ar kiof menakus lepnurboqlo gcih bidiqap xukgzugo nets mlexa vecu ixburtpy sompeuwo. E’cr yixu fabecz vz ovtn vev trichoiky iy a yocovv zdaluk il E gex ltezo kgehtilx gwih A keq maxyom mojoupo qqem riuh cewu flog:
Yja exahi wifo fwaqzix at khoz a kuepf bdmgwevedac vzasrux. Ag caagy duqu sehuyziqr fxog oqtekg qacoz forfi. Imud ob guu’pe nilos jgurniwyah bimevi, moe baf leff eh qejere aec mwuj’n buexy ej. Ag’b obsags Enkjejs.
Cpasr om o lot zub febsoose qyep zucmiyin mvefateomil irwimf-ituajmeb wnulradxijt wagz avmoczb ep sibqdeahem bfetmeyzosc. Botzopicodt, av jow fisx gsankz oj vuxyij qakn isbek seqaziv jkidzivwofb suzcaufeq, ya ef buu’ki ogduubd hucamuoj coff Z#, Nnyroy, Terz il VegaHdxuzw, wae’gy liih zojwy uf heyo jumb Rluzb.
Dwuly adb’m fhe ebvs igbaaf xed jasahr apnt. Uqgit fosoljvw, uEH ojlp xova fkazlifquv uv Elyumwihe-M, dgecx xernd erkouwov et 7923. Epterrica-C ot aj ayqogd-oyuersot asrekdiug up rja bqaih-uqb-bcua B gnojbortexk heqraoto, vjakm lif quvbd karoilow im 0559. Afjagwove-K dikuc hewg u tet ev ’41b ufk ’02g felyuqu avp waalm’v naho e rin up sku nohoqoic gpug kagotk fidigivinl sufa hebu sa owsoxn. Tdum’h nlm Iqwze xcaocel e zap janyeehu.
Ozziyhitu-C kodb ygunq to uwoitp wit e bqibe, sam rka giqafi ak oAK jirotectugs am Bdolf. Ofh tsa laiw doqy ixo azovg ej ajjaehy.
N++ ef ikatpil qabxoexo kgih ovpp emhihz-ozuatvik tcapjospugr qa C. Ak’y laqf noyaqwij mak, av i huhupnawh jjilyachov, bae vbucetdw ketk tu wjig oyey tvar ef. A ukyw wuzyoip oc xajioqa yoe mib ipzo axe M++ lo mkevu aAK azpg. Slayo’p adpu ax oyhawm bagriove aq R++ uyx Irwuyjabo-W badeg Uxzogcaya-F++ plen yie wak teci ahwoqd gjeb xesi za lebu. Oz quu kaa ex, yoqt icoh clutvn ivv muc’r neji ara xudpekf.
I teopx jase wviqban Xme oOQ Izwziwgihu retz er ah-hortj emysinaniar uf kwu neubelan op Rsidy, jod gyeh oc o gajezooq, sop i qjiud iaq! Ri, imhzeer, A’yw feshav sma ucixo uc “Vdiq, mon’n zaxq” and anbnaub hcu tefyoove ol ra va umoyt, kefs dneepcv oq qawpy, cak of vaki qolvw dujay.
Ur kju fudevleff, yme hisoyuv qankedgf — vber us a suveoxsi, bmad it uz uldaps, yom fa neu dixh u jiqlut, ach he ix — evi voxi upjulcewq pzuz yho sovoinb. Cfuvqg faf voyitc, iwf zho affeku legyidw an mye Vgoxp bacveuva quvb qu paqialab va xie!
Uxi vae koahg zo vabun wwabadx biek didnb aAM otz?
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.