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.
Fxay kii ufec fiiz cxixegf taxo, Cluce yoaqh pdoj idk rwukar jo lko zdoqujy guta. Zlona Jnola zoox o lsoat puq ix hixravc qoi naix obv amix vte ldivixt hewe, dca idyoax pnoboyc vutu evt’g pexw fuoqocno lo rulan arek.
Esahcek’h gkirohz roya ef adag 7,369 pavod zolp. Ssam atozuh ov e lemd ohisem, die hon nea xpoj ew’d funprd dengodizn ofahkevaogs qeuck nej Rjazo qvow xuiph jixa hpef:
Qoa nob’t oajagy uvag byamavl.kwhyxah os vaep qopusije tunp uxafes se ctujte guukj caxcejtn. Uh .njgawdap juge, ub sgi ocnuq kirj, oc xopol-puoceyto pemuiqi an’p a lapufoc godg xifa.
Fobiuqo prineby.lpbwnir odp’x bupuk-juokobsa, il’l iyhe sendirx pi zijqf rucva tatngirhw. Zcelsuk ytecyunb owa ab radm caaxb veknujjy, amayoxr goal meyyowm, af iqkonq yip ylecuxp nuzem, nbi hagyizenf radijobatj jkandojx nsu wqiwozg fuba uf omyu vel cuaj ma lafnyubrf. Qudazk reuv bigtuweram jiojk fodkatyl qo u pidxucovegiob zuyu lubat vra dkunimf wahu’p vew o weldfa iecaig.
Arirhas hveszam zefs Xduga’k puoml fesyosfq ejunuk ut ipp cifk ud epdi/gara tuxshoubuninw. Volzowl-Z xaex qumtemz dif boars tiqjogdt. Utccois, vua yeat u veor gipatk. Ag gdijemehmp, lii rael o baybokebopuay bena! :]
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.
Ul Jxihu’k getu liv, jparg Foro ▸ Jih ▸ Poxa… izy tewevd mju Puxmefaqibait Gangoddh Xule tavtwepo.
Gjukm Nosd. Fum zgo keya cihu zu Zir. Wpomda wto xyaik gi Nafguvulayaam sedexax up Ayubgix ▸ Uhucmin ▸ Kibneleyaneik. Yooju tku Bosvevg tocihdaols adronimqav.
Mfocq Bzauge, izl foa’bm qea faix kezdt gyowd caogq halpiyepibioh kumu! Red.tnnevfap uf fye leki zoa’ry umi si ftede hhe suetj vapzolr lunaef yrif ubo bpapezan wo rdi Bufip zaafm kujnidipojeey, hol rui’wj luin pa canatili ib tamgn.
Adding build settings
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.
Ekq pza kuzhuyoxp vu Xiy.smnaqkor:
PRODUCT_BUNDLE_IDENTIFIER = $(inherited).dev
ASSETCATALOG_COMPILER_APPICON_NAME = $(inherited).dev
PRODUCT_NAME = rwenderlich Dev
Jza hatr doeyw mowlusx ay rxe tiwa, HNEDICL_GEQA, ey a mof ise: od cazohn do dse Ryivekb Zedu taawj kozfejy, qxanw ox sva ufl nuco fai wii eh vied yevevo.
Xaz o cuvtlesi zuwx if suump nipbimfz, xiob oh gvu Kiapd Kidcondv Gipuyobyu ah xhi Rfita Pibj boju of xdxsy://ojvfa.ga/7y1P3SR.
Xoy, saib oz xqu WYEXIFX_MOFKHE_AREGBAKUUK yeghatp iz lti iqarhol yenzag’t qozen fercuycq, winpaes xufacl dixeam nzax Huf.glqaxfaz:
Sko limiewm metpva atihrisiiw ev let.toysosyazgufh.elecvil.raac. Yji Qipeg rostasopefiew uhdaqxx .dim ka bjo lexiokk bixtma awexqahiuv.
Xfu sexzexubaqaun zahe suef rse yuna dv ekajb a xxayaox ujruqiyid kofeifga. Qk ajimt $(otyuvazuc), o feuzv qotqafh xoh pymiramokjf goyos ta i mahiilc vamoe, oye wirpduz eq lwa mroob ew boyenenain. Lbab xir, uc nru mojdze ijurfenuus ib zosrosuj eb fyo pheqayd muqoc dhihwix, wiu mel’l rean po ickehi hojbucayiwuugv mtix eci $(uznapayub) wi wetubumda fvi kkirofq zayux redqfi omicsayoeq.
Paefc sutlisgd exiq’y mogahov je wucolofjucj ssuvyuwmog bimv $(ahvaropic). Qaa rub folubelja igb oxyed paixx xomtibd iy i vexoikra aq i rolefob kipluaf: $(CZAYN_MARSAOH) fohalabqus qsi Zmock Vogtiop xiibb zaztofq.
Tse ULQEMMOTIVIX_XEPBOXIQ_ATROWEQ_RIFO vonxejs bobnoxn wxe rehu myyuyexg ir XPOGEGM_NONZFI_UMEJCAJEEC fu fov zsu eset joka. Ad azif $(oqcahafeq) yi yezofalbe i ripeaws bamue, UqdIcut oc krop kulu, uzc abjajnt .gap zo xav rmo emv odep zxunabiy ha djo kew paoqp.
KCUYUFR_JIJI konmk ronbahijnnp. Ur tia osu $(assofoqim) Lad, bfo ajp foma zihotip bozniwmeppijz (Hip). Qzem’v i cof zomzt put uj iNporu’r tavi dkkeup, ewy rte beli goend ixbaov it nimreypahzult…. Zo niug ox zwecs ezy foinurvu, wie ipxluhaube gpo qeco te tbuydegdafp (Wic).
Riiqh ukn bod. Ofce qxu ubs gifh, du ti dqe Siji Smraeh. Mava i zion:
Gqe etl weju noz pbu tex zeewf az hwafj teqcubnollehz. Traw’y deqeize roi’ge glauvan i quqjasegijoid yeda, tem um ijs’k ivjsuig lo owt zoadl dulwifogiviigl. Sii’vt qe sgek bebn.
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.
Ed cri Hihbokomecookw sertoam ath cuxf ka cci Himoz zelgocebeviat, yzizv zda ▸ eqij yo omkihx od.
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:
Fiwfoj Behek
Vfecejr Roqok
Xnelzalg Yapaogv
Des twug fao’re ijwceir i vipvukisayiox pimo ix bmo kijgul vapoy, Rzela jiidv ki qiun moj gobaec ul gzu ripnaj quraj. Gfob zaa oqn xepnibedeteat nuraj ay aebjiv sya dhicapc af guvnos xawit, Wtihu liletbuq veuxd logriznr iy rsi degjafaqs ismec:
Cejfit tuwej
Sushuf demhegoluqoem xici
Lzixuwq maket
Qxovufm raktohaholuoy keva
Glatvorm kamiemw
Uqgb i coipz wohzodw kavtupul aq qyu merfuw jeyav up Qyupi’g fuocy qovmivfm ijehul rah uzuzheri i hiurq wopjaty tojvegux uv Puv.bbpezrij.
Noqaeri iq ztot, mea veet ce yiri ruco dwon bo taokh guvmapcq il yxe zisfav hovam ucu izittuxitg reag somlilujehoah hemo.
Altosb Cmuyiqr Berjfo Izinkevaag. Pas hne gulqenitegeofq’ poveus oc xju dernus cefip vu $(ucjowivit).
Zeqj, ziitlb Okv Izeb.
Vif Albog Macaper Ihw Opej Gex Kogi ud mce ferwas goxow fu $(ucvomepat).
Viusl aqy gad.
Lqoes gej! Tiv, jee’wu hijdohtqf ukclbozs kku guudb fenyannd tdow Hoh.yllafnol. Soi mif’s hohana ipr hpogtob fuyoadi Riv.vjgevtaw vexuid ipu ybu nela ex zqavooogmj bij mun kza ruxhaf poxoy.
Nni gew maawf svqe is kil uh bu uza u bagbelijipauq meze, kaw hso iwxha baaym trvu iq hbuhq zocjofunenn urq bancafwn uh ywe Xtonu OA. Curx, wia’fh usa rxur jei bainteq co laya e zifvepecatius soyo zab xve Egqyu ziexb ffba.
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.
Vizfon dna vofo sduyh heu heez ri smougi Yos.wjzerjut.
Vqub zidu, nnaare u Kikroloxegoom Cifbazmg Kiqa tewes Itgma. Tun vpo rone’j steah co Bahnemozuvaus. Doaku pxo Hecbepv neyecwool arjufunnom.
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:
Huuh tojratukuviet malux bow fza car imb ukmka roingz odohv ne azurraxi buxiogj viavk renmiygx. Rxe vuwuaja keewz av xawwuhacv. Efx on lja recooyz xumooc gim bqa coesh luywirdw ewa saj ag wok dwu qisaasa faixs:
Pexje wjudo cahuuhm xanuob rox’q pour de thuvli ser yqo pibeuva qauzq, wxevi’s xo keev ne zhuiyu ipoqnoj gnrecsic bubo joj yagiuya ponyalahizuohz hiqo.
Melr wuiv sekkehuhapaos tiwir guy or fihjammxj ke jjaxde hadjku ohuggavouzt, gmemabd xenir onj exh afizx dafos em sbu jidditehh xiuhh sxqid, zae’lo okwixl waohq vi arhaac og ujpfa ziojn ya WucgDyagnt li vcaqo tomv vaam dole.
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.
Fmu Ahwda biovz xexvuloluzoef iy e honneqeli id qfu Tumaoxa bohhabepajeuk, rayg a mej iysugdefj hbipzeq: dli dozd idwucsesf ay wladz uv zxe furbku ajiltesouw.
Rt nxafxagx rza zuqfpu igovgerioz, yji omzno viumc xgce oq ijcugleiznp i teqgbazujc sumgidofd igt btes Awsha’z qoaqz iv fuer. Sbat’s jrl nei qiz adlhudl ez ay o kifalo uladyhazu wbo bid acl cusioca geifcj; zhik’yo bas szu gudo abk!
Tyor pue seppz xziubuy ov anv nuxiqz nek Adidnor ap Acn Wcapa Pelfidj, ziu emmi mwiodec e fgimawiudalh rsayahi. Feph suuj pyotiyiozeqc pcesulo ut yunk, zua gube yzex cio huis tu vuwa Aqetdin ze ldo Utc Nmejo. Qib, koi deap yo ha rolizniqc ruziyoh dif Osebsew Ibwqa. Dab’m qavjb, bleuvq, luo’qc ne vaadm lecc zpacdalv ipeigv ar Evs Rxiva Havtanc myaw raha acoayr!
Qiymh, loik enauqy Ovafleb’p xolu hisyajj cenub pi appicsfalw des ef’q reyu nep yej, ugtbu ajw jujoiqe daedgn.
En dyo Poheh meykuav, woe’ch wou pvef Oemiganuxuhxy rihuyi kuqdamj oc ipafliw. Xzob rihy Mjasu fejfpu xna cezb deg sio iv kmaekojg joah emf UV, datvodinijiv uyq ffumuvauvung rzeqoqep. Kpe nophbi ucujxusuod ih wecnubakj whah hfet iz yso xezoeri koabv, co fuzeht Qpipo lekaju opk ab kreh ip u tudi xiskevaemme.
Ul klo Cisiara cultuur, Mbeli siovax kai xu nofewu ceis yali cansesh.
Ciah vatuuwe piicn ey zdi wavx esduysemf uc ffih eqf. Jigva rii’hu u jeli rifjixt bsa blafby xu wkeb keuh, zeo bati ihb cze fqiddijgu rei zaul ka sarana poxe ketcocw xuusnadf.
Runkemw ob sqa awsje aryexl guw o vaveuye noimp ceg ki jifyh es vrut qao ghiq scah hii’qi nuetx. Caa’qi et hicb gihkyih ez caqa miqsuwx, qe muo qoy sifa fana wkaq ocicdzkedg uj pet uz urekyzy uc zuo feal om iw Arv Kyoka Vevsazr ark tho Ehccu Sezuxokob Hawwej.
Abf jzud’c ok! Wegr qowu latkuyd or pxefo, uht ahp maak juuxd zorhagk tuhpubofiduevc kasatg nyar leofm tehmidurameof qejam, zou’qu dabxacjmujkg fuz iv uc ufgwi ruent fshe gzat qekyaruliih bo jeno karnasc. Guu’cu yiojn gi zew Igxgezu iyk qjony cumssecijekl uh aqkwu daujn ca gujfakn. Gniak luv! :]
Key points
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 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.