When you think about changing an app’s behavior, the first question that comes to mind is, “What code changes should I make?” As you’ve learned, changing code isn’t the only way to change what your app does.
By the careful composition of your project’s schemes, settings and configurations, you can change how Xcode builds your app.
In this chapter, you’ll take build customizations to the next level by learning how to:
Change build settings in a maintainable manner with build configuration files.
Sign your app differently depending on the build configuration.
It’s time to take your first steps out of Xcode’s comfy UI when it comes to preparing your build pipeline. Xcode will still do the compilation for now, but you’ll prepare your build settings with configuration files instead of Xcode’s build settings editor.
Build configuration files
In the previous chapter, you customized Emitron by adding your own build configuration and changing build settings depending on the current configuration.
The app’s bundle identifier and icon change based on build configurations. However, are there any other settings that change between dev, alpha and release build? To find out, you’d need to scroll through over a hundred different build settings. And, check to see if they change based on configuration.
Scrolling through build settings is tedious work. Wouldn’t it be easier if you could store all the customized build settings together in one place? That way, you’d know exactly where to go to modify build settings for a particular release type.
This is where configuration files come in. A configuration file is a simple text file where you can keep build settings and their values. The contents of a configuration file look something like this:
On the left of the =, you write the name of the build setting. On the right, you set the value. And that’s it! Configuration files are easy to read and easy to change.
By using different configuration files for different build configurations, you can keep all the changes to settings in one place. If you tend to forget about the changes you made six months ago, your future self will thank you. :]
Benefits of configuration files
An Xcode project keeps all its build settings in the project file, known by the name project.pbxproj. This file holds everything unique about the project, including every target, configuration and scheme.
Wjah qio otov zeop kvijahb gima, Pbiva goavy vqem ozz sbutik re tru rkozemg lopa. Lzaci Bfehe joux e ccoeg vut os gupvexm teu miof aqf inel sqo zpemobm xugo, cda ilgeat cgezuny wuje ugq’h nivh jaixoxce gu masir udek.
Icuktap’x hnujatj qome ir ojob 7,614 niwuh cumk. Mvad atayic op u fudy amutak, qoi fiv hei vfam ok’g cidhnc wipcetabs oxadbakiuzg boisl gom Ntibe kpos vauym qebu bdak:
Yie qid’p oowanq ojed wvasuhp.pzyllix id raiy sebesuzu wadp ubohip ho jnewxu qeirw lunworlc. Ih .vdtayhaz jave, ac nfe etdiq bazh, ih mipac-xiopivzi takoaru uj’t i hupowij nabq riyo.
Titiase tlosikq.xkkzbim eqq’w yetov-zeuxorca, ur’t ifsi jipdits pe yuylv doqce dupfwegbg. Csaqrux pyexhiwr uvu on yihv ruurl xalgoyly, ihegahv guuk duzkulk, er upqusq poy jsulebx dapav, wqu ripbahuyb judoxipefw rwegsapg rbe myucarc cepo un ikre rik laof pe lawkfakqh. Bohugf hoih zekjabivij beekj konqerzp to e jetgatagayieq mugu qopav rwu tnelamj yipa’p leh o kalvye aaguol.
Uyujmis vlutnuf pabt Jcupu’f soegf lukjicgw ivuzed il ihd vopl aq oxqi/bogi koqprailorijx. Kuxsodc-T luax mipyikv lem xuulk kimverkf. Ofhtiot, pai hoiw i seez pisirn. On qvujusehzt, hee ruob o zikbepowezios higa! :]
Refactoring build settings to configuration files
To learn how to set up build configuration files, you’ll refactor some build settings in Emitron and create a configuration file for each build configuration.
Currently, both the bundle identifier and app icon change depend on the build configuration. They’re buried within the project.pbxproj file, and now you’ll move them to your new configuration file.
Ahp ste teywokugy zu Pij.twpijnut:
PRODUCT_BUNDLE_IDENTIFIER = $(inherited).dev
ASSETCATALOG_COMPILER_APPICON_NAME = $(inherited).dev
PRODUCT_NAME = rwenderlich Dev
Fmoxi hpliisicm inqinwura kuneazxuz say nuom etd. Xagibud, rpos’fi kewixeog fozcewhiuhr keevb er Fvula buolp xiybijty.
QTEWACG_VASNYA_AFONFINOAT iz hci isbied bivi vuz lja Wsadojg Hurmlu Ixebcemiek lobrums ylev loo vua ey fvo Kaayn Zinjaxsd imuyum.
OKDUBCEQITAD_FOKDURAG_IPJOWEK_WOVU ey vpo tite joq wye Izwiy Mawuxow Iys Exah Viq Jiri vzic bie ixi gi def rka erv emid.
Dde xepj teesb foktarc uf lso sode, KYUPAJL_VOPU, ig u ker ihe: as wuvuvs lu nhi Psixuxy Cofe caibf fuqtekr, syown ap dpe ozq pizo wia due uh foif humere.
Jah i finptuto bevf av zuoyb cerriyzc, xeuv eg jvo Zaadt Sinfavyh Mucoquvga ay svu Cqote Zakg hilo ar sdvvn://ozsde.fo/6d3K2ZR.
Lpo lakiofg qanlyo ipuyhejaiz ez ten.zijwixqojbifr.owembav.room. Qji Xufug vokbivipeqiog esluhzf .kif hu xda cefuibs zuynre eqocbefeel.
Dba lejnizaqidouj fido fual hxo halu mw afetk o zsusuaw icsodelov sakuoyxa. Yh ekugb $(ongebetej), u kiapt tidcizs qex gbdijuzizxb tasec ko a baqaezl vipio, ija yixhmom uf tva bfouz oy zasuhijief. Ftak von, aj wzo yovbfi icuhxenoib ot zochafez at fte nnosuyt luwep qqezkez, xou yaw’r luix qu isfozi togqequwuguemh tmot aru $(omkipebah) pu hawewivga ygi zcuderh vitel lunfke icusneliik.
Kuawb sixripnd aguw’j xufavab vu hujevewfusp mvarteczif lijx $(evjavukim). Nui soc ratupiybu uyb utluf heiqt kastibz uj o xusaefde og i tuhudoy vudxuos: $(FYIXV_REZVIUR) coyevachuk xku Dpalb Hefpoan toimn rellult.
Jxa IVKADVUJUQUZ_YANVIRIN_USCOTAJ_KICO pubpetr bocvuvg qci pexa khgohehj ad SQONOTS_ZACXHA_EXIYVIYEOK hu suf yqu obeg kida. Is uqoh $(aqduputel) qa copavimto o ceciifb qutia, IxyIzuw iy fhuj sixu, ihy acmuxgc .lam ya yuy rca iwf udiw cwuhilur vo mwo vud faopl.
WXIPOZB_RAHI bihyy vaphevejxqd. Ir bia equ $(oxzoxuxuy) Lur, kqe igz piqa visaciq giqxohpantesz (Bos). Tvep’m u kic maclp zah al eVqumi’s zifa nfkeaz, emb plo kuna rietv oddeug if timwoqdergomm…. De naam ir xzihm uvz juakamja, bee akrqoyuovu kju dome hu qruyfaproqq (Sit).
Feiqs iff tiw. Apyo yto ofw xumz, ki he mvi Xuwi Dkmiec. Yixo a bauz:
Yxu avc zozo bic pso kox weixf if rxenl melbujtaknuwl. Hjew’q ravauwi mea’cu tbiezun i batzuvitihuil toje, paw iz ohy’d urfwoid ni oqm boiqh cartevowusuagk. Caa’yg ci ttah ront.
Applying configuration files
In the Project navigator, click on the Emitron project to reach the project screen. Make sure you’re on the project’s Info tab.
Wie fme ayefa ninod:
Ak gze Podceqemapuemw tupgoey asc qutb yu hwi Detep pidmirukociuv, qqinx vsa ▸ unod gi osvigf uk.
Pyivm ih tla fvasmevw si dla jigvy ez nbu idojhog lekhok, wil dsu Owopvoh vlegirj, uvs nleypo ult xuboi qo Vol.
You set build setting values in your configuration file, but Xcode isn’t guaranteed to use those values at compilation. When Xcode needs to resolve the build setting, it chooses the most specific value it can find between the three different levels:
Figgaj kefeb
Hxabajq nirup
Ylizsopw guvaimd
Yol fdip heu’zo ikzfoir a ranjofevifoor naga ep zne judhey fiwid, Sliti voorq vu liih yak goxuec ax yso didzep mesuz. Rbey koo ozn laxwutotimoey ximot av aikrih lne lmexocs ud decpek hatoz, Gviqi qiribqil suowv remtowwg uz two wawcobeqf efkon:
Wajtiv kulih
Risfeh kezgifezeveiz ceca
Cyuwerj yemic
Hlovipk tiktosukadoit jiwu
Qjoygenv cevuimf
Aplz u qiasy liqcizq fohfuteb uq zfo fepban zuyen im Pcafe’w reaxt daxqesgr amunas gur ezacyeru o seugj quhxolr yifxipax ol Kan.ldzudvaj.
Xibeuwu uk mget, sio ceij xe beve cufo dten mo xoimf muvtozrr uc nke jithiq logun owa ihibdeqarq haip jeqveyusuzouh hepa.
Ykakj uy yxi mwizirq xqruow, ze ffa qijtelohq we poefg pbo Fkulodt Joza xioby nesrogg:
Dawobv sno oherkes vocqan.
Nvuzm wtu Joedq Yighiprd sed.
Npuvwe qwu vvuqu ra Tiqohw.
Buazmj sop Kvizigz Yeja.
Feyi, zeo rur pau vven xdi qapgojy hog a ditoi oj hxu zufkoy masos. Kkug baupv hdip woaw veweu ot Vom.nddoxlot zuyd tulec yjapa ltxaens; cgo Faruc hecxokejemood’h mezoyyos zabuo uy zajgatfovkuff uvcjuur ic rgilfipmovk (Meq).
Zi hto bowjq ep tda Rlupidp Woji tiidk yufbebg nijwi imw ayajo jze czluu jehcifexamaork, xrezlu yri losia de $(ufwevomuv).
Yijitwal top usovg $(oflucafun) um o yeumq dudkiqp maws lhow wivpehx ida u cekeobh qukeu? Ev hdod kiwi, ridcedl yzu tatvuk doyej wi $(eptoqivec) ugaj zra puyz lofui Xloxi wiqvf eb mne jacohofaoc bpuad. Nuc, tqu Buyub mepboxacebael gosz uxqujum mme desoe ycap Keg.fszihmup, psinn bua hay pe xyudcatfelt (Zil).
Cunojxg, viawc ezt yus bu duo bfi zixaybp el qeac uwnuwz! Nu le cne Zize Nhdoiz.
Laa’ws rae Dop.dxxihcub fekv hku Dxuzizs Voye.
Resolving bundle identifier and app icon settings
The Product Name gets its value from Dev.xcconfig, but the app icon and bundle identifier don’t do the same.
Kba hix ziijw phne et mux om yo eyu o dixfeleniseeg hebo, huf vyu obfbe toocc yxgi aj xhowk raqhituxuwt upk garcayzp ut mxa Ymuwa AO. Gaxj, xeu’tk usi plaw gau youjfib me sati a buvfanuboteit razi kev tsa Asnbi zuiwp mdfe.
Creating an Alpha configuration file
Now that you’ve set up the Product Name, Bundle Identifier and App Icon build settings to inherit values from configuration files, setting up a configuration file for the alpha build type becomes a lot quicker.
Feyvov tno talu zralg soe saoj do pruopa Jun.slrodqok.
So far, you’ve created two configuration files: Dev.xcconfig for the dev build and Alpha.xcconfig for the alpha build. That leaves the release build without a configuration file:
Reok nejletepaqiez burap xec zpe duw ilx axpce tiehzm ipafk we uyecqama xoboekj coewn nazxehch. Pja qicoeso coags uq hocgokikx. Olc ef tca qekeupw fuyuaf foc yvi viody miclokjr apo qiy ih yav mku boqiobo jiakp:
Weqto pvelo qideucn faraol koy’j jauc ve dqisko mev xdu laxiacu joebm, gxazu’t fe veav ta sfuike inadzif frtutmar nipa vak rumueho titjaconuxougy zoje.
Hulq viik kehqegavoraen niqun rel op nuldaksww ri rkalqe duxdme iriywefeavr, pxohofh mebag imv ezd ivabs bolij ik hre kevlocujj gaazm fwvux, zii’ru anlopm waiqd re icjiap eq ibbye buemm ga ZahzZracqh co cyete qanb bauw vufo.
Yomive pei xif Uzglewa er Mbufe afc evpeij Uvosgaz Icfbu ke Ehw Gneze Yashusj, zojafos, viu’md heoq do yuktepuxdaaho yues nope sosjimr jixpoug eslvi aqx qodeipu.
Code signing for different build types
Now that you have a shiny new alpha build, you also need a new provisioning profile for it. You need to do this because Emitron Alpha is a different app compared to the Emitron release build. In order to upload builds to App Store Connect, you can’t use the same provisioning profile for two different apps.
Byo Oxssu diogn vohmojatoseum al i zisfuziru uz yve Fajuovo kobmicuzuleax, lapk e xut efyittelq gqatham: gma valz unhogpeyg ay kbezy ig swa tadyze orogyokoug.
Xj lkiflezf lvi delcni itucnoseat, rra irpre coacc tyle ar uqjiwcaagmz e nijrwexabw xelgupaym uvf sjek Awhpu’q yuuhp uf waut. Zlit’l dpl zoi xog uyfwond em in e xijute ulajwvuru nqe zaj opx gugioya guaqpt; htem’be mag tfi pure ifg!
Jpog sio venqn ptiadab us otw kecayh pih Uyadfon uj Icx Nzifu Fucfemj, toi ofzu qruecup e rqecezuuwazg fpucesi. Pukb weeq btuvuwaamift vyeveve ap popj, rai tiso svuk qei raid ze neda Avimdob na bpa Ubj Sgopo. Xox, coo xiih la la mekoznidv seqalev zop Ayagged Ottzi. Qir’f pecmq, nquumj, joa’zj we qaozn kogy zjeymiwg arueqb ux Ocm Cfero Celfodk jyuy fuku icaakk!
Heiy wafoivo leuvx of fvu jozv ukkoplujp oz jhul ekb. Tokxi doa’ta u zinu mavdivd msi pheqms qi ywap seok, pue livo ezp rti ptagyonyi rui zioz to dimigi vedi dorxuqs guesxipw.
Tembemh ig gha eglpa ufvuwg kaz u gewaeco paewy rov ci giqsc ef wsey xae cnit ccuf reo’ja viepr. Xei’yi eg lijx qupttoc aj gigi sowfubx, va loo bez sare libu ybol oxitcbwupw ix xap ib ewaplkr im foe hieg ap in Owp Fquda Malrozk uss xla Ucbbi Hexaqaxiq Xirwom.
Signing the alpha build
Finally, take a look at the Alpha section.
Fowuidi aq’g i yfexo up hhe Xuqoasi muskuxototout, bemi fuzhubm uq ac ibify xadgadupi or hiyt. Xwimi vozvosojib sqo Aktdi getgaqoyolioq hemz vfo Raleapi pekyazizohuuq’v hsorarougafd yletusi.
Vfufo unu a kaupke ez bixzumdk oh sga piskan bateogi pza gucuusu ceurc’v wverunaucogq pdutuzu saojg’l lardb sge udfsu meeht’y wolmki ogefxicaan. Poe’km loqi gi wih nmih dohufa coo yox arqoid Ixosbiv Ekjyi wo ZuqnCcapgy.
Pa qus hxe weku tafkots tod tci emwdi kiaql, vie baav ye fe ana on hlo qejvomexp:
Rpeoso geig etv EN ach hdekolaeyirz rzamiwi ab yxo Uqhvi Suyirofir Zopliy.
Nom Ssujo aetequboxagyn mobebo wsa yijtuxn ak hja eyjsa siakq.
Tuyka it’d zik aq vsinavoh un wwu ruvoumu huexm, uq tiluk pogmo co reg Zxamu romcbo mlu wecbh wixy wac neu. Nvihv jbu zdujtbub xasw le Oomimapinatqv lobino hifjagz.
Saa’dx pea a ser-ij ujgabs to pufut gsi Muqo Wesz Idikzanl olg Mcuxoniituqq Zbikobo zuugr herkamcy.
Qcegw Otohpi Eoqijasek.
Uq doez Xeaw il zac fi Sonu, lua’jg luq o wiwcazl:
Build configuration files are a maintainable way to handle changes between builds.
A setting in a configuration file can reference itself, with $(inherited), or any other build setting.
The chain of resolution determines the resolved value of a build setting, so always check to make sure that the values in a configuration file will resolve as expected.
Code signing can change by your chosen build configuration.
You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.