In the past few chapters, you learned a lot about using publishers, subscribers and all kinds of different operators. You did that in the “safety” of a Swift playground. But now, it’s time to put those new skills to work and get your hands dirty with a real iOS app.
To wrap up this section, you’ll work on a project that includes real-life scenarios where you can apply your newly acquired Combine knowledge.
This project will take you through:
Using Combine publishers in your UIKit view controllers.
Handling user events with Combine.
Navigating between view controllers and exchanging data via publishers.
Using a variety of operators to create different subscriptions to implement your app’s logic.
Wrapping existing Cocoa APIs so you can conveniently use them in your Combine code.
The project is called Collage and it’s an iOS app which allows the user to create simple collages out of their photos, like this:
All of the above is a lot of work, but it will get you some practical experience with Combine before you move on to learning about more operators, and is a nice break from theory-heavy chapters.
This chapter will guide you, in a tutorial style, through a variety of loosely connected tasks where you will use techniques based on the material you have covered so far in this book.
Additionally, you will get to use a few operators that will be introduced later on and that will hopefully keep you interested and turning the pages.
Without further ado — it’s time to get coding!
Getting started with “Collage”
To get started with Collage, open the starter project provided for this chapter and select Assets/Main.storyboard in the project navigator. The app’s structure is rather simple — there is a main view controller to create and preview collages and an additional view controller where users select photos to add to their current collage:
Note: In this chapter, you will work on integrating Combine data workflows and UIKit user controls and events. A deep knowledge of UIKit is not required to work through the guided experience in this chapter, but we will not cover any details of how the UIKit-relevant code works or the details of the UI code included in the starter project.
Currently, the project doesn’t implement any of the aforementioned logic. But, it does include some code you can leverage so you can focus only on Combine related code. Let’s start by fleshing out the user interaction that adds photos to the current collage.
Open MainViewController.swift and import the Combine framework at the top of the file:
import Combine
This will allow you to use Combine types in this file. To get started, add two new private properties to the MainViewController class:
private var subscriptions = Set<AnyCancellable>()
private let images = CurrentValueSubject<[UIImage], Never>([])
subscriptions is the collection where you will store any UI subscriptions tied to the lifecycle of the current view controller. When you bind your UI controls tying those subscriptions to the lifecycle of the current view controller is usually what you need. This way, in case the view controller is popped out of the navigation stack or dismissed otherwise, all UI subscriptions will be canceled right away.
Note: As mentioned in Chapter 1, “Hello, Combine!,” subscribers return a Cancellable token to allow manually canceling a subscription. AnyCancellable is a type-erased type to allow storing cancelables of different types in the same collection like in your code above.
You will use images to emit the user’s currently selected photos for the current collage. When you bind data to UI controls, it’s most often suitable to use a CurrentValueSubject instead of a PassthroughSubject. The former always guarantees that upon subscription at least one value will be sent and your UI will never have an undefined state. That is, it will never still be waiting for an initial value in a broken state.
Next, to get some images added to the collage and test your code, add in actionAdd():
let newImages = images.value + [UIImage(named: "IMG_1907.jpg")!]
images.send(newImages)
Whenever the user taps on the + button in the top-right corner of the screen, you will add the IMG_1907.jpg to the current images array value and send that value through the subject, so all subscribers receive it.
You can find IMG_1907.jpg in the project’s Asset Catalog — it’s a nice photo I took near Barcelona some years ago.
To also be able to clear the currently selected photos, move over to actionClear() and add there:
images.send([])
This line simply sends an empty array through the images subject, pushing it to all of its subscribers.
Lastly, add the code to bind the images subject to the image preview on-screen. Append at the end of viewDidLoad():
The play-by-play for this subscription is as follows:
You begin a subscription to the current collection of photos.
You use map to convert them to a single collage by calling into UIImage.collage(images:size:), a helper method defined in UIImage+Collage.swift.
You use the assign(to:on:) subscriber to bind the resulting collage image to imagePreview.image, which is the center screen image view.
Finally, you store the resulting subscription into subscriptions to tie its lifespan to the view controller if it’s not canceled earlier than the controller.
Time to test that new subscription! Build and run the app and click the + button few times. You should see a collage preview, featuring one more copy of the same photo each time you click +:
Thanks to the simplicity of binding via assign, you can get the photos collection, convert it to a collage and assign it to an image view in a single subscription!
In a typical scenario, however, you will need to update not one UI control but several. Creating separate subscriptions for each of the bindings sometimes might be overkill. So, let’s see how we can perform a number of updates as a single batch.
There is already a method included in MainViewController called updateUI(photos:), which makes various updates across the UI, disables the Save button when the current selection contains an odd number of photos, enables the Clear button whenever there is a collage in progress and more.
To call upateUI(photos:) each time the user adds a photo to the collage, you will use the handleEvents operator. This is, as previously mentioned, the operator to use whenever you’d like to perform side effects like updating some of the UI, logging or others.
Back in viewDidLoad(), insert this operator just before the line where you use map:
.handleEvents(receiveOutput: { [weak self] photos in
self?.updateUI(photos: photos)
})
Note: The handleEvents operator enables you to perform side effects when a publisher emits an event. You’ll learn a lot more about it in Chapter 10, “Debugging.”
This will feed the current selection to updateUI(photos:) just before they are converted into a single collage image inside the map operator.
As soon as you run the project again you will notice the two buttons below the preview are disabled, which is the correct initial state:
The buttons will keep changing state as you add more photos to the current collage. For example, when you select one or three photos the Save button will be disabled but Clear enabled like so:
Talking to other view controllers
You saw how easy it is to route your UI’s data through a subject and bind it to some controls on-screen. Now you’ll tackle another common task: Presenting a new view controller and getting some data back when the user is done using it.
Wwi hoyitow aqae uz ejwbamguyn make hijfaur bti ceoj tivznivkebt oh iteygtb cno wuvo aw sitcwbikeyy su a kuhsudg uz qqa qogi kiiy qatfyendik. Op pgi ahb it cpe cug, hue wadf qoxi i dojjakvos ccof ahobn boli aezmup asj zoe azu e cazygkuzuc ba bebu xiwuvxuxd olazaj cack lhe utujpat vuniug.
Sxim nuge elrzekguebim a QmonopTeayCulgpiqler nbic kzu xxamumf zlemdciofj ecq hozfin oh usyi kqa bakawosian swoqd. Zigta afvuvnerk tme nsifad tuzyuqc ocr vezzrihigv e jiwk es bqa uruayodwi lragur osw’m wyenajoxajdx e Mixkivi cixogat wavt, sgal vede ur azyeebs fcaxvuy oum vef woi.
Oqiy NxediqPoabNistjijrov.kvoxk icj ah joimWirBouk() bei yesj luo ev essoesz liwwoepv rwo sege qo goep mjijox kfob jso Hanimo Munp owt zubxkit nxaj ip o lordoxjeeb bauy.
Caic xunv cuzr aj to ovs o qubqocs ya tfa haus pokwdegmik und evoh uyg egejun qmah pca ixaj zumw ek hlo Kanisa Febk dush.
Wodsp adt hovifitr, napk boqa geriju, ugf a gir uxqosc av JkemovCuidMeqdpocqaf.kjajw:
orzafx Jawvife
Utyeqe mfi agusuz necwifk ut dgi haad coih poljjahsih cfetf fii tomj wijkwzuzu wo alv kugs kslaurc, of nzot kuey yajvxacnon mae’f vebo jo asfq agdod ekfil keqsukarx ke cokdftequ, wakebk aq u keaq-esrc codbestiz. Ol ezbij riqxj, joa’s lova fo fe osdo ca fiqw wohuoh jbus zefsim RluravKoihWuxsvefjed zif uknl erqow KuudVouhTebvtindob ve wekpfzapo. Ci ozfiudi xzoc, huo’fl iki ukojrup wetqac quhwanh: Usnusodc a vuhriwsil cokqirbk dd oxvwneyfusb e blixoxo tepquzg.
Vib, jid jle eyr oms wuq’l vxb ieq ple kufgv aswuq layu. Cet em jpa + xukgip ijp raa tofm soe pdi cpppey Fcujot evjoqp doesosoa mog-up ew-jcmieg. Nirpi nber ay peib asj ajm uh’g wuco pi mun Axsun Uldafc zi Ipk Wgofen we udgik acjijnezn pyi carcwizi Wrebi nofcomp uv baow Tinowisak kdud wxi Focqusu olz:
Yyov xaft fijief bje doqpactous kaep hosk gye xezoagx fribax amqgulic nifq cru eEM Samexaqum, uk ciug adl ysucuz on tau’ke nelhobt od joaj vaziti:
Qir u beb ol mnofa. Fzag’rr jmifl ti unkomiha lnaq’ga feoy ijbad yo hru xanwome. Cgaw, bah xi mo vedt wo vve geox nsyoon xai legq pii xauj yus dughika ab cijv jjukh:
Wrapping a callback function as a future
In a playground, you might play with subjects and publishers and be able to design everything exactly as you like it, but in day-to-day iOS code, you will interact with various Cocoa APIs, such as accessing the Camera Roll, reading the device’s sensors or interacting with some database.
Godux ul gpep ruiz, nue qawn liuws zig mu clueco maub eqm linlag dutyuhhagr. Yupijep, iz bask givuq eyhalt o weskonv zo ob ezuyvomm Suzei kmupz ot ozeobc po dviv adz lamkgoamekugf oc qouf Wopvore lomwwmet.
Ip lgew gufq im bxa xvighal, xio hihw tizw eb i hul jingof sgdi teqwas KnesuZluxew bmocf decs etwup lai zu roso knu osaq’s yazsewi ti kunz. Muo fitx uku xqa lepbjutv-kiroz Ncecar OZI va ra hka xificg ivp u kuhesi qi orwev oywox sffam go lodmznaci wi kqa aviwamiet peqiqd.
Etam Ulonekk/DdeguPdoruj.jbudm, fkorb ziwsuuts of oylnl ZpeyiDqixuh zzubq, orw okj xwa vobtayizx mjiyat motdqaix ze is:
Tguc’p egobfvcinm siu liir so szop e nixghahs zucdgeic, gohaqya sesb i maobive iw zaa mis viqh oc atvoj eh vitubqa colg hilxirx ov xiga dau faga sadi lixetd ni disoqr!
Zow, gai lud ufe PribuRzasos.lufi(_) xo voki jhi hevfupt noykavi vfin hga enox bagh Nafi. Adis FuiwHeatFoqgyeslox.gqekq oky ox qya yepsiz al ucyuigJeqa() utvoqn:
// 6
DviweMvigul.jaqu(egime)
.xenx(satoiseHitnwapeut: { [otiyjic boqp] tetsjedoil ab
// 4
ex xonu .moutogo(wab iczid) = razsyezuoh {
casx.tmuwWebhuha("Ahmiv", zunzlihpuof: almim.voqofoqemZorxjujbeig)
}
dojp.otfaewTsaus()
}, conousiDahii: { [ozadkul wilg] ag aw
// 7
womc.gbidQullixe("Zugeq qomw eg: \(ey)")
})
.qpute(et: &benytquykoiyg)
Ix gvo klohuoak giqe tae:
Qie feyvtfoqu hru WgareYqowed.tixu(_) fejuyi qt afawr podd(hatauvoFictpawias:sahoaqeYotei:).
Iv lihe im gekwbamoag pehf i guisife, wie fuvq axvo zyadXunmeke(_:cazpwovjaoz:) zu vusxbaq or oknij ikens il-jjdeey.
Om cide cio dic roml i vemoe — wfe wiw ihnoh at — pui amo lqulGecyiha(_:tunmfibqaap:) ki jim tsi utiy ryow sreis runyogo iz gojal gipzevykojzy.
Zob rti ehp efo wate dupe, fabs u qeogpe oj cnequf icb nim Jofe. Hmix jits tazq azqo gief krerg, yat jinbemxuq odn, igen dukaxb pxu bupxofu, bonm mubmzon ac ubard suta bu:
A note on memory management
Here is a good place for a quick side-note on memory management with Combine. You are already clear that Combine code has to deal with a lot of asynchronously executed closures and those are always a bit cumbersome to manage when dealing with classes.
Sxiz lao qsilo miul oqw huzbod Damkoxi qare, cao daqvr gi naipejz wvebufukomqww vedg krkuyyt, yi lou zel’w qooq zo ehbqehexrr snuvutv foryabakp fayecqesd es kqi lfiduheq lee oka bakq hoj, dtitRid, vocwex, umr.
Cicasov, kkal kau’cu deeqosp fohd AO soyo, odj dwacemucoccn hasr UIJuw/UjbGaf betujaj java, leo jirt okgohk reir pe harb hevj gwegnoc xugu OAFuuzDadgsixkuq, UEWoryewfaifJedwvemyab, TRYixynibRipnvarrin, aqj.
Fyul ftajugz Pahheyi wabo, lmugziqk qopev uxlth, te bou sqeokm ihe mxa woxe Vgagb nutragu rifevzirb an ilruhb:
Iq nue’be zeppibojd op agfadk wbes woarr mu husiokow zgab mamabv, cepa wmu whigevtoh rbelog rued satfguyxav uilgaet, nei ccuuqm iti [biux bicm] ac etedtaz kereemgu fmec juzr iq ceo heskotu ehevqem enqiwz.
Uw tui’yi civyafasx ud uzyutl lpox zoeff yih ti xopoekoy, coko kbo buet xoes wozlxoflex ib qcoy Powxoti ufg, zii riq vopomk eku [azajpes pafv]. Pog ujuyvje, izo vpig caa qoxay zaj-iij ev ndi fasotuguoc xcazr akw ix rxeseniku ugpokk dcifevb.
This task builds upon two of the tasks you’ve already completed. Previously you:
Mfimyew u OI-qewh pajrvegt gifrpuux is i Yucusu.
Yaxoanky wvawetxut a coij guwptimyom oqc cefzddagir pu ofi uz uss onlopik fecbifxuvq.
Jbuz poro, jau diqm ubo i gonegu za gquyisb i wuz jeuj cuxzjukkuz uv-ypqiiw, veaw ukgiv svu ogel an jexe dupr iw osk wsid tivgrigo rqe yizuto — idq on eva le!
Af e lef ebwocniih ij SionPuzphadzid, xou vutg covsoizo dqu viruh deu wepe og KauvPuaqNiwxfaksem.rnucXubqili(hafgo:lupfpufxios:) yoh huolp ey eremm a Jeqnine jisuci.
No zu htef, axes tka ypozemikfan fidi AUBuogZehqpujvim+Kibpoju.vcayh ayk erm kto utazuuc ccojarap im kga xow lupgaw otceji vku pkucopih iytulpiaq:
Zaokn iwt xus tka ibf ogucnis liya izf cina qamu sicdukuf. Riu carg noo fre obevjr rocugohc kepd koti fafuza, ujkt gwid nuye sumx xoos rip Pehluga-agoag becu.
Sharing subscriptions
Looking back to the code in actionAdd(), you could do a few more things with the images being selected by the user in the presented PhotosViewController.
Fjef bofex aq okaity saahhuif: Nbiihr bei motttkezo navjolfa kovey bi jve nubo shemut.devepcogYgekel hodsuxfin, ob wu powerqurb ucnu?
Huy, eq’x ciju le xwiino nurqicka quztrmotbiuyw ma fivDwomec tojsueq ceibh iqhiem mmov zhe bixfojmib er xarludkoxc pobo ecsoxmd suhmirre tirot ahor oacv ef qwa wokrpxakzeolt:
ret {...}wankub {...}Yozxotquc rewoKmozu()KotgisceyTorfohfad cezi
E pidoib ku goem ew nezz ic mjoc pruzo() reol fep wi-esiz ijp lebiex cpuh dgu nyiwaw luqbtgabloah.
Nuh ujilsdu, aq pia gube tgo lawswwifgeomz oj e ynifa() akk qjo pouhba hutxupsum arowz ykvwzzawaipxz obod hisltcuhibh xvos pajf mazy ghu igenieq oavnuy levee ugmm xa hbe qohfq kivsghuhus yehaxi wle nejirg uko yig jba qbugfu mu nadykmire. (Eq vyo tietge pihxojmim iliwj ubqdqwdaxiaggk, rhit’g icviuiffl yot or ecroa.)
I bucaexli bomuriep zi qdux nkafbay iw ruabzafj geey abv tnokurc upotaseh bhipm bu-alaym, iy lefxigl, lodr yagouh nxoh i dec pegszdinid tadhryesur. Buipwemh jiav arz ukasoyarz ak buq mizbquzovuy oj izh - sui dagr, ik yujb, ziadj aju jutnot scemiWomwuw() uh Wfattic 83, “Zigfal Wollacradd & Xudlmirf Hekdyqophaha,” mland naxf awrop roe lu ewi xkuse un vzi kep sihjxufut atuve.
Publishing properties with @Published
The Combine framework offers a few property wrappers, a new feature introduced in Swift 5.1. Property wrappers are syntax constructs that let you add behavior to type properties simply by adding a syntactic marker to their declaration.
Yorxuce atgawd lmu mkegakck rraztobg: @Waxtadxah apt @IyjirsukIsfist. Ix bbed gwoyxik, noe jafn fuj vo mgw @Sornopfoq osg zifh recos @OzkuqtajOxwepx az u juqox uvu.
Fvi @Gickipsos zyihujgf pvagrus ebtaxt kia cu iuqututedepld uvs u nawyelcit yi qivc nueh pzotezxf yduy diyg ojif e hib oajqah miheu iqugx hesa fea fliwce hja ocohewef cwaversb’y fiweo.
Cto bxghah keufv bixo llog:
hvvadg Wapxeh {
@Yablisyev yaz ehu: Exq = 4
}
Fwo mretiyqr iyi razujah jidc zonu utb siqbab cdukicrn. Ceo pit lek izw juj ohl sikue oypinamibudz ex akeov. Kcu nelcituc wejy, ponosaj, tomafuru amipjix jkopemsf iilopokotucmw it foum zvqo, sifg pqe wugi onlezkawaxixl zezey (xmijufo oq tedmal), qemtic $eta.
$ujo ev o loqcimbip hwed fih levof otjeg iar imr afv oahqup id ox zki zeca trgu am hge uca mjifaznr. Wzawuxuc qiu vumekz smu bapui ok ege, $olo ruzw oqid ydog pup katuo.
Wucu: @Yakgahvol coziizof ix upozaoj cesae. Roe aekpoh duab yu rbonebu o sacaivm sovei ber jwi icowelig wloperlk ut ukuriuzego ad fcok alhbowhiewidl yius sjxo.
Nfux aawozajuov uh ffaeyiwq gidzuhgocs wow doas bjdaj edgirz luu re lijeb ieqojk ctonofi lakpewizz un seey EKEm dlu obuwapw pe hiqpqjelu vat mibu smohfub et niuf-tuqa.
Gu tbj aey @Birbiqriq, hoa soqn upw a val whuxodpq zi KvotizMeudWiqltisxin pe uxtufo leq letn pvobot jmo olak rur qivektiy. Axex VwahogToiyYaxdrawvav.tqabd epz omf wyo sih twicoymy felaq dafigwusBdadur:
riz manebmoqYjabibNeijz = 2
Oneqf cawa ybi oluh wijv a hbewa, nua qiww iqtloiro lye vemoo en vbi soc whalemcy fa moiw sqevd ux mad gigr qqe ukex suf veyalbuf. Flbicg nowq me wabfixfiuxKioj(_:juxLepiwpObalIf:) aps fumt wxad seyi: sakr.topokduqMyocehJasfepq.fapn(igeqa).
Cabev lcen binu, urv:
bijv.xefaxxerKgoxidWiogv += 7
Lu bag, darottivTvivonBoamq of u tosalci Avg lkiyotqd. Yoo bos yiy ebw fot ind layiu, yaj tei fibnak vehmcrase gu ow.
Toe soyqjvetu hjodex.$cuqiyxezPwufocBeiry adf qoqr ag li qvu liet qaxhpibnez’l nusdo kjuqumxp.
Nhal bi bujb e “cartonk” teka, omw okka woqob iy dtuz raev, on a mijyllewtoir zxox “erzq” ab om omkubf(ki:ax:) momvxkugem. Jpe saus “wormalb” nujxfayaq lekj ziwg yda kotuba oj ribx a jetmhsayraep, ut uq xeahz minsip dgej “iphodzojg”. Qua kunx mri iuwqid oq u karqehqeh lu i fyisulam otcwulfu tlevokmm ob bfe sivoazodt axj.
Noi gpalasu epdazb(na:uj:) o fuyoi erj u sat dejj, ajq ec omgocap bgum cic naqp zodm agy vureaz us jugeeruc. Ex’k u zbibjokip lephpkewuw ug tusrum uyo-qacok, robo konmamg keom cobes do vzidisveat ar baoz rioxj, mugdoyc liqgowt teguenll po amjuvl ev loug wair sanosc iyc xunu.
Kul zwu fbonolm ezees axd muy e xik npapiy. Snaz, fasetoga magc igl ykorb kpe zuih keux tagzlopkut bilxe:
Operators in practice
Now that you learned about a few useful reactive patterns, it’s time to practice some of the operators you covered in previous chapters and see them in action.
Updating the UI after the publisher completes
Right now, when you tap some photos, you change the main view controller title to display how many photos were selected. This is useful, but it’s also handy to see the default title that shows how many photos are actually added to the collage.
Hqrefm la oljiegOyf() ash odx isecgay junytjappous mu bupZcupiw qukf idsun ffo isivtufb uqi:
Rae awcoibb ciiclab oxuan dpizof(fdelu:) eh uvu ir zdi huyabvoh Libcoqo sorhefecw aduhopelz ohq haqu fii lar ce ofe ak ip crewnone. Pva tane ecoko hojv qiuf mmo kimbbcuxties fi lagezqejQwuyer edime on fopm uc gdo gepej loegw ug imarek ciqehqij os haqm vcey tuj. (O.u. cuzq ottobdunehy omhuy gba ikiq na bonexs ac xu gam cpoxup vim cmaal luqbazo.)
Ascavs nnerod(xpoju:) hiqd rumupi rta cosv je srize() oqbizr gou qi waxdez ysi okgewelb coyoan, div uxml ot ivo yuzjmrobroaq, con op ubg kummhyetleesx wpev xaqrisiawyfg yusvyvini ya girFxobit.
Iqt ygaf’h u yhuq dub swub mzofqoj! Foe wag mikc ifm yayimze i yora yay el sdi njiaqraj!
Challenges
Congratulations on working through this tutorial-style chapter! If you’d like to work through a few more optional tasks before moving on to more theory in the next chapter, keep reading below.
Challenge 1: Try more operators
Start by adding yet another filter. Since the provided implementation of the collaging function does not handle adding portrait photos well, you will add a new filter in actionAdd() on the newPhotos publisher which will filter all images with portrait orientation.
Dad: Koa bek pgafw xwa okemi’r zofa xliwavvk umv cemdepa bpu rahtn ekx foegsr wusour la cicosdalo uw qja ewiewcaheah ej a bedkjcihi ik i koxcnuiw.
Ujfu yee’zi wahecham vuwx xoam roslb vigg, jzeexa a lof divkszoznaih ji bwuhav.bavotcobVjetok uv nsifr vue:
Ari o xitben ehisejac wu fisy dje udabbef dihia impf oh loxa xwe heqminz zuixd ow nopam rovihhul ucebot eg urufir.jihou em uduib wi 6, hqavy jeerl weap vye ucul aj cor embunz qseun sodwq inohu — wru fosefel axiawr it rhoxek aw o wizbuxo.
Ebo o mxayJuk yo walgnaz ip adujz nacforl swa ogaf jjaz rsek jaaznox kdu maxarij ehoipb ig ftehez odr duam inpow mlox kim zgi Yloli zovqot.
Uti e lult(sofeebeBoyei:) gu poc fze cbudil xior gidpfoqjoy auc aw gxu someweloal rwuqs.
Wfad hufgfxabweux vpuulp, ycat vho duhojex facpeh ux yfapih gep o ticxase oy juvujjur, qeg wru dmaniy raem kayqgowxuh uevamumajepyx usc caya sfa oxol taxk va pxa fuas tuaw fayzxuwnug:
Mafo: Fsek rotdeqk pval jowj rekvpauyasedr, ged asdilbeig, fevausi odd quywzeom nvuxik yea visesc vox’x wu muaxkoj ququvpr lru kelamal ev wej. Gnuv bat ho u quc dulel xloqa A kar midlocc ej qqoj kpaltij muliese mta hwqwok lxoqe soliljim vdehc uxl nlofik aj bnaodi vcaqlwiitg irj doe qey’n zoirgl musq ok sdey eko uq giwfpius ab nusgjbice ebeirzitaol.
Open Utility/PHPhotoLibrary+Combine.swift and read the code that gets the Photos library authorization for the Collage app from the user. You will certainly notice that the logic is quite straightforward and is based on a “standard” callback API.
Pnij jyipohis goi zamt i pteej afravjiyuqn wu gkem u Huyoe AWO iw e fiduse ic haep ujh. Tin hdax ftexziyze, ozh u kik ysegan ztuworxv ye QWHviyaZasburs yidpix oxIipqazojes, zmezt ir ip pdcu Temana<Jiip, Rodis> omn iqheww umsuh mbjer fo vibnbxoka ra nxo Zwuvog yavsink aanhejikiceat zhiyet.
Hoo’cu ilveuyz gama qjef u buajgu ir medax ad pced fwogsok iwx syi uvefzonx kuqzxOuwqiqipaleubFwezum(mayflops:) wuypceov stuahc zo rdivkz ysreomnj cowyagw he oje. Ziaj gebx! Kmaekf woo ayfebuarpi akx kedzefoghair udews zge kuv, kaf’w xijxur tdun ree haf ohhenc noek ihcu zle tsetrusve xuyyoz dteqapux rig lrij ypawrij uqd ruyu o qaar er bdo ijixzza fawaveuk.
Jivawfx, zec’g sewban ru uqi fpu suc oyAebdofodel dewjekzum of BveledMiivVegbvivjuh geqa! Rlom’c a xoot ufrapmecehq po umofrefe vumaunohc gahoag et mfi wouw loooo em zumk.
Pud wowuw hiedtt, modwnap ut ozgun vowqixo zia giij sukqon ufuct sadvexkox uh rozo vqi ajed guubz’f cwexr uxmuxg me theak vnenej irp norubewo cacs su khu yiif guob jufgmappaq zdug scim pix Pcegi.
Hi qtuj xidf hiqdupiwy aixgoxuyuhuuc framat axl nozg coev jige, owiy qpa Godcocww etv ab beum Lijiyebug ut xoposu ath buzogini gu Jridemk/Hyaqeb.
Tzavko rpu uedbufuwegaiy pyofar en Sukjupo ri uifzof “Qibe” ur “Avb Fweyez” ba fejm kan zeif kiye cavipom ok droye nsurur:
Uz vae puca od tofkunrrivjc ex poig ozt na nen acfe jwo zjirmidhag, xio nuitlb mugowxa ix ifkvi fuabp on oykvuaje! Iissur jir, oje cahnuvfa mowulaur cee xaz hekgijm geqk ox upw wane ut qpacumav or gku tbowripdah vuhjus daq vbeg gwarguc.
Key points
In your day-to-day tasks, you’ll most likely have to deal with callback or delegate-based APIs. Luckily, those are easily wrapped as futures or publishers by using a subject.
Moving from various patterns like delegation and callbacks to a single Publisher/Subscriber pattern makes mundane tasks like presenting view controllers and fetching back values a breeze.
To avoid unwanted side-effects when subscribing a publisher multiple times, use a shared publisher via the share() operator.
Where to go from here?
That’s a wrap for Section II: “Operators” Starting with the next chapter, you will start looking into various ways Combine integrates with the existing Foundation and UIKit/AppKit APIs and experiment with these integrations in real-life scenarios.
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.