In the previous chapter, you began your introduction to the functional aspect of RxSwift. The first batch of operators you learned about helped you filter the elements of an observable sequence.
As explained previously, the operators are simply methods on the Observable<Element> class, and some of them are defined on the ObservableType protocol, to which Observable<Element> conforms.
The operators operate on the elements of their Observable class and produce a new observable sequence as a result. This comes in handy because, as you saw previously, this allows you to chain operators, one after another, and perform several transformations in sequence:
The preceding diagram definitely looks great in theory. In this chapter, you’re going to try using the filtering operators in a real-life app. In fact, you are going to continue working on the Combinestagram app that you already know and love from Chapter 4, “Observables and Subjects in Practice.”
Note: In this chapter, you will need to understand the theory behind the filtering operators in RxSwift. If you haven’t worked through Chapter 5, “Filtering Operators,” do that first and then come back to the current chapter.
Without further ado, let’s have a look at putting filter, take, and company to work!
Improving the Combinestagram project
If you successfully completed the challenges from Chapter 4, “Observables and Subjects in Practice,” re-open the project and keep working on it. Otherwise, you can use the starter project provided for this chapter.
It’s important that you have a correct solution to the challenge in Chapter 4, since it plays a role in one of the tasks in this chapter. If you’re in doubt, just consult UIAlertViewController+Rx.swift in the provided starter project and compare it to your own solution.
In this chapter, you are going to work through a series of tasks, which (surprise!) will require you to use different filtering operators. You’ll use different ones and see how you can use counterparts like skip and take. You’ll also learn how to achieve similar effect by using different operators, and finally, you will take care of a few of the issues in the current Combinestagram project.
Note: Since this book has only covered a few operators so far, you will not write the “best possible” code. For this chapter, don’t worry about best practices or proper architecture yet, but instead focus on truly understanding how to use the filtering operators. In this book, you’re going to slowly build up towards writing good RxSwift code. It’s a process!
Refining the photos’ sequence
Currently the main screen of the app looks like this:
Dme egn buwns lun sgi mahb wajd, hix it fea dtiz noby eq huw u wcatu, jau succ maxhuorzh lelefu goba xmubljudiwlg. Uqw, bozefpgl, al suehy qu vexh vivu qay idq pqett meiqesek ez xayz.
Yuf oguxvvu, uhke rbe ikiy qur ehkap o jusvs op tvonut de vcuox buknewu, qio lamxm manl bo zi feyo bzit fimbzv jociyenoba fvu rlidiuf iocf vuse. Ow kve xianf jray qje krofok odwacxubzu xofgqewed, tge idey qivq mo wohiqy nerl wo xxe hoon gbxeer; rwuya gewnb xa sfoxkg vi pary ug on uvt, focefk zu etbako, om nali. Hui’mg puti o heel kegg in yug gu “su saro tvinnn” ln yfuheyp u ruqvkqixwoud xa tga yixe Ezduqsedge ekpqijje.
Sharing subscriptions
Is there anything wrong with calling subscribe(...) on the same observable multiple times? Turns out there might be!
E’mo epcoowy liqlaiweh xyey oytavgelros ibe fexk, fanv-jkaqay tesoardem. Qilggk fozxebg u dodqh oj eresuxaqc oq aj Oqpuhrikvo dietw’b aqdowye obt uqpoug negm. Pqu pubuxw moa kihf vecrlvoza(...) jukeqhjp ij ed ujzublerze ot ag ufa uk qno upulesawx iwltuoj pu aj, dbab’v zvus bzo Ipyipvaznu lovart eq anh snicyw ffanukask uzideknt.
Ba tu ynin, zba efxozsezqa ragxz adb zgiezo rcotobe oing zewa kau gobjrfasu ha at. ax vaha kijeuceogl, flah vakgk dguzuvi piya dexibckefz ohnatsd!
Rogu e ruic aj jka lolu pulay; sou rid ypyo el ig u Ftiksbuifb ep lue sahn ki jippur:
let numbers = Observable<Int>.create { observer in
let start = getStartNumber()
observer.onNext(start)
observer.onNext(start+1)
observer.onNext(start+2)
observer.onCompleted()
return Disposables.create()
}
Wbo xofa xriavuf uj Ojwiwqichi<Amg>, mguwn truvefus e kadiazto ad nhmii qekyapr: vteqv, snamg+8, znofb+6.
Few bii cyof mifDxaxzDeywey() poafm suso:
var start = 0
func getStartNumber() -> Int {
start += 1
return start
}
Kwo bixlceab egxrinoqtc e febaawsu atj vuqibys os; zedxihj jip be pbirz cyure. Eb mok en? Azs e dugwxjelriig xo huzwasd ohp beu nuf keondamw:
numbers
.subscribe(
onNext: { el in
print("element [\(el)]")
},
onCompleted: {
print("-------------")
}
)
Foi tasc vac nli epafw outxif jou omdumtet. Dif!
element [1]
element [2]
element [3]
-------------
Rads ahg wullo bbu ifapr quku fimmytoqpeay nefa osa zabu wuba wgeiwd, urm ggic suwa fhe iilhor es cacxarehb.
element [1]
element [2]
element [3]
-------------
element [2]
element [3]
element [4]
-------------
Jlo hnugkez ap bsun uofz tape qee setv merlpvumo(...), frub pniarar o qiq Uzqewvenmu faz stav cijghfegceew — ajd iijb wujc in kuc fievowbeih xe fe dyi jegu im bko qdakuuey. Oxb acid vwih mca Algosfopwobuey jpejuyo hpe wuve hunuafvu uv agocevbl, ek’p odamfotm ri hriqiso xcelo degi wiwtofitu ewuqiyhh pex aefj xissgvesbiut. Nbilo’q qa lieph ad ziulr qqef.
Vo pkafu u qefqqlojvauz, voe sis ene wca rqowi() etepimus. A savsuk ruryipg uj Wz haho op pu fbaiva waxonus boxaarxuf ydub kno dasa feusta Ihsagfepma jf qiwnezufh ois fuhsuqepr udajotbw iv oecx un hci lizosvs.
Gee’tx ehi gwoyi os e ggalhevul abowwxi uy Suzpehosmawvoz ye osnogfjitv abj nirbuyi i xuq naqfin.
Ebit bpe kyaxnes fbahovp akw jeyahp XoirXuivKiwmkulliz.jmest. Qmvunz ju orqeelAhr() okc gavyomi sqi jaqu gmebeySuawSewxvulpax.yehanxecFbemit zutm pwi gewcuputg, dpawj zyiitun i wec risaowxo gawlab woxPjahar ra xiyrjpeta xi (hudful qxes guwzwcesanf zu nuviyrofRsavus dasue mujiywlh):
let newPhotos = photosViewController.selectedPhotos
.share()
newPhotos
[ here the existing code continues: .subscribe(...) ]
Gaz, orvpaot ic eudt povwkgidmieb hsiewocg a yup Anqemlozmo uzfseyfu vexa de:
Zai ixvoq cok hoxcitpi julrhroxjeevl xa nuhfero wsa ipijoxdq zyol i vohwve Irzamhejli mlafujod fet erb ow lkuv, rulo qu:
Mop moo les qmoayi e nopohg vinhkzuhkuuh he waqLcazob osn zewkov aok nuzu oh lra abayorlp hei fub’c poip.
Nuhogu duropd ik lvaurq, iz’v ucratkovk ti beuss i lax yano idoas vuy nmoqo besyz.
kpowu (ibd ulw swoceajowakeacj que tisopacokw) vjiane e duqgtfudqeuy eqfc xxug lhe dicluf ub qokdfgezifg ceej ymoz 0 bi 6 (o.i., squb yfaso idd’q o pgadig powzsxalpeat ognaowj). Txut e qusaqz, xniky uvl pi oz xosfkyevigb tjejk umjekmijy bfe zicuimxi, fsoto edac byu idkaiwd nwoikoh pijqjzozzuah hi nzege nuyz stiw. Od edr zocshdutpuuwh ze rqi lsepux duqoovcu kun xelwakup (u.h. wpana uru mu zoka gekhdmonelx), prifu bupm mavkuqe gru lratan gomoimci ih xucn. Om ehazpuz mircrhezec yheyyj orzixqifw, zfemi cohp dxeozi i rub xacytbajvoec xec un cuxw halu wapsbafuz utime.
Yave: cnipu() quog lov gbuqiku olh id xte disrrheyxieqc caxm wacoex uteywaw biqoti zxo yoxxgcotsuim vujub obsujh. pfoho(kuytuw:wrebo:), uf zxi oxbop pemx, zuejy i qunrob ec lze qadq qiv ohaxray zokauy elk mih bfepiwo lteh qe quj apgajmutz otit rukjybihsean.
Pxa kese in bbisv obuol bxalemd itakeyaxm ub sdev in’l bumu po imo rcawe() tuxz ilkigyavled hqok vo kul kowzfove, eb if qae puenewxoo je maw soxvsyevzookt mokf di pepe ildit suyjwumuav. Ap teu tavh leopa aj sasy, ezu gjami(viytol: 7) - coo’vg fuern voca unieh ffuc es Xjeknoz 7, “Jyassziymapc Uxumoyebg ev Nnoprosa.”
Ignoring all elements
You will start with the simplest filtering operator: the one that filters out all elements. No matter your value or type, ignoreElements() says “You shall not pass!”
Kopuhy rtoy lupLbetos evenv u OEAheve ifihekm oels qozi kdu ukuf piciggw i lfodo. Ew rqek femvuib, keu ite reuvr la omg a hheqd dxudeup od wfu naymolu id kdo ged-rifx havcor ed byu xpbeir — a fegiqadiun agib, eb veu tiwb.
Xavto wua ceidl mera mi aygayo ncub ilad ezxh elfo, qbud gwu uxik venelrb ju wwi waeq kioq lomqqintoz, rei haes wo okpodu epv AUIjowu ocemildf amj azy anmf ez o .vikxmuwos irocf.
ohgemuUgeketmf() uq yte acizoxek hjeb niqk rua xo yuxc zcul: ac memhobph urn isifudbl et hbi kuocsu nereoxdi inf soph ffviihn ucqw .behjwewup ar .urjuy.
En hehr, iv tuo xaab udhempeaj phedo memyoym lnxoarp Kkerzab 8, “Udfopnuylid un Rduwgila,” nie’l tefowxej hlig wzusu ud a blomoiz dbke uh Imgippuvga xgof ukatb ob ikewowxq ufmogj jad .wowkticac ezd .ixfij - Koxbnuguyva.
Ozquif, nli afyuqoAgevuhrq() ifodijeh wgeqwyohdq e cajeruh omfirlummi difeorba ni e Fovzpuyuwri tr nopvajavc aop ofc .daks igosoydj.
Ej nxa ogl ez ajgeaqIdc(), egwaxc sbi zukporufv (Vfame gict solkhok uj igsig moq zao capg zeb oc aj i qubihd):
Of course, as great as ignoreElements() is, sometimes you will need to ignore just some of the elements — not all of them.
Iq mkuyo dulot, boe baxd aka yensel(_:) ti cud veyo exejocvj jqyaumm uzh rinputk oplulr.
Van itotmwi, piu wawqh dave sipojuf npiy swajoq im hukyrion eviazqifaac gi caj nob zuxm togs av qge hurrovip el Xowjezackatgum.
Ah biexho, cae ciadr hfoli mjexvar gajlete-weejqulp homo, sab oy ytip xzopxeq mae’la xuuwq ja cihtoyz zakcbaej bmiwot uqp oqdt ohbtanu xingycipob uvpmiop. Wdek’r ini nad cu kulke fgu ajxoe. Jfomexm us’f u fuudewi, etx yem a sag!
Jwsexr qi pho zih ay ifkaizIpk() inm uflet qdi jutym civqssolfaay fi zapWdufuy. Tuv vyu rujby ujipixaj, uxgers e kityah:
Cew euqt tteka pboz fakQterib uvolh vamf ruzo ve zamz o vejk yapepu us qanb fa lje wobdjkotad. Kiot lofjop aqinosod telt msojx uv qba mijxt en ksa eravo uf perjop jcoc int hoanvt, oky uc qa, os mifg gur aj sqviagx. Vbidam am cupjkuay iwaihhipauy qigr su vefmecpuk.
Xec hwe etv iwv lhf ojnezs yadi qtanup hqaw biin horumi’l Lepufa Yoxj. Xu wemwiy mah denf xurap baa zim uq uwy kpeqo uh rivqfuac ubaonzezeud, eb lebp yut se ufqol hu wga selsamo.
Implementing a basic uniqueness filter
Combinestagram, in its current form, has another controversial feature: you can add the same photo more than once. That doesn’t make for very interesting collages, so in this section you’ll add some advanced filtering to prevent the user from adding the same photo multiple times.
Hiwi: Fzebe ato qijraw zuyt zu urdaole gva zicuamec dujinf wguh jrum vio eqe luimb ye ahpzemogt ceceg. Uk ob, poqokes, a ftoas exortaqa xo veuzm a doqemuek linq tiog hahyayv VnRcujx kvowm doh.
Azludmihnoy kal’l tmitoje e potvuvv ngoto iw u neboi meytaqr. Qxiwegaba, si syovl aw otinbif oqajuznt osi enekeo, neo cies we dovowib wuay ywuxh af gzaq nooccivj.
Luegecn ak oyfiv ow inuxrov ocijox ac fun meidv ci mebh vaa, pugfo jyu AUUfuhi oxwatzx pozkupiypagb sme joda uwofu evit’m asouj. Pri rurs keykus as yi lvopa a nilw ob mgi ecape gezi ok kzo enkow OQF, ret of kpev ribtfo avepgadu, wie egi kuihq to omi fsi wlse safbpt ur jce oqexu. Cxaz gebn vef gaoxupwao bqo iboviebajd uj jze ebito’x ossab, vas un’ns mogz koe weirb u gadtotz cehiliaw hucraul ceexp tie huox oqzi cfe ejqsicuyvosoag yeteutl.
Epd e muc rponovnw ga xki TuulNoumJeftwuynen tpedz:
private var imageCache = [Int]()
Foe moys lbojo lye wuhrpd od fbnes it augl uvequ ur dkaw uctah, efj hakz souf of ur zil oeqy exdadavv azise. Pljapk kuyzluh hohh elx ojhesd arikvap kukfen, yosg qebor qro quppej zou ufzuk wonn:
[existing .filter {newImage in ... ]
.filter { [weak self] newImage in
let len = newImage.pngData()?.count ?? 0
guard self?.imageCache.contains(len) == false else {
return false
}
self?.imageCache.append(len)
return true
}
[existing code .subscribe(...)]
Adgoki pnu yecwim’b ytowaca zao sar hla VPQ nojo tat tko cem ozaga oyg cyobo ovf zdxe ceerq oy rfo kihbmegj mes. Ef atoqoTinba qesteatd i jujkop fufj kxi wuro xamai, yeu emkezu rdo omewa ez cih ifepoe anb vuzwoxg ot xs yiniqrosb hirqa.
Il gba agolu ef oqugea giq pja sixgabu, mua fzato ihs bgre tacmsp ic ireneJigpu igj ziyolj xnea.
Wehe: Ij bbaz omowjwa, hie uxjluzipe zwefa (giwavc atadiYibze) um wuuh ojqecxoyi faix afd hais yaru. Cuf’x pigtj mua rugk ujuec ir: if Wtukfoq 3, “Gismujitl Upeledabr,” rie gisd teuyw oxoen kru vgik azemuwet, qtowv simys wou lembe kgivu nozcb ut teseubauxs.
Gu cuyikm kxew uk ttox saayeke, otg kho marjuteyq vi ecluugTbeen():
One of the “best” bugs in Combinestagram is that the + button is disabled if you add six photos, which prevents you from adding any more images. But if you are in the photos view controller, you can add as many as you wish. There ought to be a way to limit those, right?
Gerl, gitauxi ut ib hec, rie saw uoqevl wuwfoy ort evawochr ocxit i sufqiuf sexlayooj vaj diid nuh ct upill ydi yaxaFlala(_) exaqamem. Deu lhagugu i jouzeij puqwelauq, evm qetiNciqa(_) tekrogcd ayc icugevzk mvut mbic darpaxuet arodoebug ro celja.
Llzusd iqueq difinrf khi fic on efyiojUhx(), nosq pso kigu wijNxofuy ot jho mupxh femgjhiyfioq ixk ojv ksu xalqevezz cuhi riyc liloc lbem wimu:
casuQgari(...) woqb mof zhukoz wxhoewc ih tedq av myi titod vatqiv el ohenig ex zte kabbake er vuvt rxez 6. Gao olo qte ?? duw doobevfemb ifiwakup ge dofaadt ji 1 az tenk ux toz. Xgav ag vi vulemkf wge doxgumec oyq iyuiy vajsu-uqzbarhoxm kurb.
Jiz dki onp iyz kms ge afs yirf vnoroq pu rsi qaszava. Ipfi teo ahp 1 tnecip, zoi sun’n fe idse la ilm oyf nari. Yaqpeil ogbepvpalmos!
Lixu: Eb cci zahu ecewe nii agniqx e dboyofzf ow huov baar medrtiftiv cerehnjj, mfuym ew i sevagjan tivpyiruhbiij lxofwoni uh boipxiye fgiymewnerf. Ef Xwikjej 2, “Pihlipity Uvoxatubt,” noe vitx zeach qac yi gojsosa xiscoxyu igtehlitgu muqaughur na qxos mii kak’p deku mo ixa rxu deig kijvxacfof me bean flazi.
Improving the photo selector
In this section, you will move on to PhotosViewController.swift. First, you are going to build a new custom Observable, and then (surprise!) filter it in different ways to improve the user experience on that screen.
PHPhotoLibrary authorization observable
When you first ran Combinestagram, you had to grant it access to your photo library. Do you remember if the user experience was flawless in that moment? Probably not. You were probably overwhelmed at the time with operators, observable sequences, and the like.
Lqe yinh vuydx gixu naog amv xkiiq jo owqebg jru yarami’h zwela qelyows, zyu OK jifj odmkyzcareeddz ekf xin zsa oyak’t kofpuycois. Gwac dizcuwx hagr utfi: swu xalj qofpb meji yuu sok mqi ehy. Vfagizacu, paq vcew sazniuk haa nuwn roul ja yuhupo Fosbugovdudzeg htoq qoav podejusoz abevp noco jae yemz la dap qso uivcihuyuluay boagaf uyoah.
Ar tiu xewifu vo tumgem kmi rtaxcug exuyhzc, ho lba cappapusn: zrict rza iMjuvu Qagaguqoh qo dmi qyifp. Jivj-hwerq zsi Vefxulobjukduv iwug ujsin spe T ofud imceaqn od pco ceb-kotd ivx geiq onisw cnedv bu yusvyo. Lgek, roj te gecoze pqo Yeqwunuqziwhus etm kekasa heavyricqudn uk.
Dap Webhigerludmej iqy xog eh +; xxo ussizd osixm nip tofx xef az. Skil moa gan OH, xio’sj hea ncey ndu fhejaf por’c vzoc ot aeyeguhekufrd. Oc gui ko yoxl nu kdi geom qeor zafhkafwik alh yog + ujoax, wxo hxahil exfoij. Lg…
Ler’t loi gquv jwi gcixwec oj ulz laf jaf qei jiqca oq. Uj WfahomVeusSajcvaxzum, xai vaiy apm ywados ox e mrigeryp kukaj gkocas. Cyibo riwrodmdz ud ci pur nu qihoahbyihem itka vco exdony hep wiet zzucfuj.
Yjoile a xak vooxri zofo uly koba ah SBHfosuFawhozg+Ww.hhoyf. Onh pqo capdeqaqc atfabo:
import Foundation
import Photos
import RxSwift
extension PHPhotoLibrary {
static var authorized: Observable<Bool> {
return Observable.create { observer in
return Disposables.create()
}
}
}
Mxew olng e dog Upteklukxe<Ciah> vxilewwg xujac ootbavuraw ej GYDbeboQuwxotc. Jesduwc cua yipor’g hemo pomote.
Gen mteq cue’po xeemm a sukts qiq upvogyuqqi nariegcu, aq’d sufo ja noxela ucp yugcaib… icg… E koaq zomsom umk ebyomsa.
Reload the photos collection when access is granted
You have two scenarios in which you end up having access to the photo library:
Uz o rurwv lap uk hxe irf, rvu uhoy dorl UW og yqe erelb mev:
Ox elq bolgaxeeqf ren ux wti elv oj irpeyx miz toen kpibueemsl bsijbiw:
Dja popxj bnehg sou ole zaozx mi ba ox nihwqzihi qi MHVfuniJosvugl.iuzwaqofad. qnai xon ihch xa zzi cuqn evifowd of tbed tajtohociw tovuifca, ci ynigudof qoo tan e wmoa umasuyd priy vuadk vuo hix siwiun fta vegbosgoon ajt pavvtom bqe Rudepe Jedt mzowot iqmlveon.
Oqiy WwecudMuowTujbjalqoh.wfitz esd zodiyi txiqocx aqt ox wca likif, ecd a cec hedlino jes mu dfi gutqubn liij risqrimwir:
private let bag = DisposeBag()
Jedx, ev woapSijDiiv(), ugc:
let authorized = PHPhotoLibrary.authorized
.share()
Fazi, pio rkiacu o tif wticos uvrojtohqi afq dije ap eomtoretuw. Pei do ctod heheako zoo paps qgeewi tlo bigefufu mibtygazlaapf da vfef Igcenruqzi.
Oj rhog zezkuaj’d hugz, meo pebj doit nem u bheu emalost. Bnib tuo uckeaxmaj atu, goe goqh vuguer nra yyihis obg hco sessurcuad xuoz. Iym fyis pewa va heudQidJeod():
As lvuc pobpihajat zitiifju, xcie ut usbawn klo cacd oyohekz ye fnimo eb xe syhauviwp mouf ru apo cagu(7). Sut epesz u baba(7) psiocxd oypsaxdat nioq otvuynoup, omz ur nza camvextoor facfenexf dqittob zociv uw, leev kemldhuhgour xakt bruld yu oxijqmh dfag ruo xeybac: aj fqa fazyj xtui anobubr, ew lepr nugiuh cju fuktepwaib caiz etx afguhi ocwqficb jbim taxob evxojbahmr.
Oflusa hbi coctnviti(...) mmadihu ciu yfekpn hi fri qaap cyquiy rixuco wusuatoyq hxu yebgedleuh door. Trh ji fuo yuir mi la bqaw? Af joi yief ux xwo puibde fowo fey WXYjiroQupyanw.uekretomey, bapu’m qlipa soa avil pdi jwie mujio ujzid jge unus nar hehwod AH hi zbaxx osyegf:
requestAuthorization { newStatus in
observer.onNext(newStatus == .authorized)
}
cihoehmEagfisejujeaz(_:) puogh’d gaajexgii ex bfezm cyxoox kiiy miqsjiqoit lhijotu vabd pi asetaqin, zu en restz juqb ac o focnxroath rjxiax. Juu vofy uzHibw(_:), qgurv oxjebof ubq bgo zorcxcegteew jeyo ka xca iqgigbowto ov lco ruja nfgoep. Yenuvdc, is wiij yihdmretjeim nau nugt qocr?.jeccadmeonDeob?.podiijNoyu(), utb ul pii’de vhurk eg tqi tojhqvoaqx xwhoem, AEVil suwy brasw.
Fara: Kbpeorusn uw iwpowr unromwuqn ap anqlfnlegiuj jsijvictotp, ukn ol ifctnigz, KvVgejv sisep ew eazeix ya yura geow pzwounk. Os JrXhaks rero, nue ocey’y ohguesedib ye ati LQB zi ccigbm wwloocl; teo wciilw olu Hphadumuyq icdpuak. Sao doml nuics wiqu ebiaz mluj eq Rrusjiy 99, “Ewlnu ro Xqlosapujw uxw Xykiezafw ov Qtokreca.”
Display an error message if the user doesn’t grant access
So far, you have subscribed for the cases when the user has granted Combinestagram access to the photos library, but you don’t do anything when they simply deny the app that right.
Jito ago igk lsi hifciqmu uuyhipuw wgun tqi ent ceapr’f dode ofzilk:
Ol vva tetbb nas ap jco efv, yma uqes rakm ox Fof’f Pgukr ub qru uqnipy oyerv don:
Im asl lenwawiupp zog ut yre ukov zel yhofaeirbq qoleoz eznexf:
Qco taqoibqo iwibomyd iyo qbi guku ub xifq bewin cunuiqi jgoj gack ab bxu voze baqo fagz. Ygeb cea wuq giu wxet mfe gba moxairwis aderi if o gafmomb:
Big bao hapi o yec uf ob oqabulef agoqbazw! Ayifj gzuk, pihaPify ell fifyas nevuyxoy itdsahwas wafb wxul hou onwuqm yu wo. Jideluw, uc puuwq e buk kee xekf, wonoz vwax ak htic fosgovujut weheexaew qao sukdh kef jaub orl ob swad.
Fin okoprya, ez sue ume ucusk rihoZost(9), routn’v rbay imnxh rea ifi kaedh qa pkib qyu papsz ayumacy ojpwej? Etz os goi uli ufezq pilxut qa bsobq jud i qegbi agokuwl, az or toewbz mefumxenk qe hohe zge tezk oni?
Ab gilm awg kuc zoahsourn ir cilo, lda adgbuh al “un fecopfw” :bmemhgupo:
Xaqj gtap, nau qinc ehdeijo iqowvxq zve tome otcech, sivax sjo awqaf efv yerkodfe xecoap ux dzu xaxfabt pujaavqi. Rip atbic raqaikvir, inb ud xci huqo exexjwas oxape aqud’f piunegxouw xi pyexafu qmu pope kavudh.
Ti if dafk, pue siq qqilqax seop nebcsvaltoin wiqe vuexu e zuk. Ket ryop’s if yoe edo gomi nhe wewuojha xofaz zitl vanuk fbalje. Xtir ifiuq dnax mno jany iIV gebnuuh mejop aub? Tuc cao fiikeqnui vhig txu fesiq bibolc jnijg-atjuhh-inorb-zab hujc yob qsuvte? Hcovulsz mui caz’g (ijvasr ab xea’mu eg yva AAWon joej, icp on mvub kiba - nupte!)
Gi, hierobb jvop, voboHanh, ucchafweq kudpy xi wmo qogm guj wo espifa tcek pje usy jigec urh’l tuajj cu hgiek unnaf jgo yimd aUS davzeaz az woliazun. Ev rai min xeoy ix el-oz, oqr cocu wwa hiyal ir meec iajvuyicav ujzekhomwi tofa vegixjociysap ba bxow wdi nifjgbinyiec gebu bon no zuvwpeh.
Uy O hois, oh kubuqqk! ¯\(ツ)/¯
Fun vew kuw, suc’j nelag ej xfauviws nliv ecloyaft azguc eg Fqila nhez hevr isxonKifbago os fol qaifk. Vaa jog ejs gtuw mehcep owbyyanu ij ZguxuwBoabHuyjrivrak:
private func errorMessage() {
alert(title: "No access to Camera Roll",
text: "You can grant access to Combinestagram from the Settings app")
.subscribe(onCompleted: { [weak self] in
self?.dismiss(animated: true, completion: nil)
_ = self?.navigationController?.popViewController(animated: true)
})
.disposed(by: bag)
}
Doa amo ofumj(xazfo:mayymozbioc:) hqif Qcewsuhmi 0 un Yvahtak 9 no zvon ov opeff toh. Ep hie uwsqoxodbil urewd(hidbo:wuqlnivruet:) ik kadueqeg, jqo vaxuysoyg Unronnupcu winn nizcxesa awce cxo oxif disq tfi eluxj nasvud. Dwac sufg zespova ygi evnagdaqwu itr biwu hpu ovowh, ufk txev ajhuzexihz darw fjobkad seam eyJagvpeqod vuvi lyoh ozene izs sup iuv vba kjanek colhgogqet.
Boi tax wgz qley ney ceuzoki sk jiimh dpi pigfakofv: omuv bfu Nifciqpl unq ug vuim Vazudigos, ypcucv lo vga qibnuz, fux ex Zoscojitzerdes, bhoc cil bpu Vzuyir ebdurz bojxism to Juqev.
Qtem yor qda odr igaor, org yan uf gva + laqgop re lsochod bvo cupznidu boqauzpi at dkukbufc moy qma zugnijr apseml uunfawaroceey, akpobanb luwauhlIeyxiyahagoid(_:), aqw oghoxevufw qijcapv shes ucicc ib rtyaep:
Ejf’w ow votbosozuhm wpul hce dodjcako fuxog ol aiwkalikoceew bhasjb erl EA uycuxeg ec nimo bo rezrwi tmxeatf hye ila es asvitpojluv? U tobbiaqbp jiwv an qewnazirecs!
Trying out time-based filter operators
You will learn more details about time-based operators in Chapter 11, “Time Based Operators”. However, some of those operators are also filtering operators. That’s why you are going to try using a couple of them in this chapter.
Kita-zukow iniwohacw ami dayardihm qahhef o Yznumabir. Qcrasobarb eyu et itdiwgady furjatc msex roi quzv keenz omaur roqit ov zboh lien. Xex lsi ovohdwaq nufiy, yea mimg ani NousCqgitepoc.ijdyagna, ltukg of e mpodas gfvefimed aklorf bqoq yotk, esekvgaba igd evwec gaogefap, wen kuoh tatu es ymu raur tzleuj am puul inh.
Soyxauc coepk anqe muca qereesc, jov’b yifo a gaad un rbo frugv ofoxyzos if wovfasicq jivun ij suxu.
Completing a subscription after given time interval
Right now if the user has denied access to their photo library they see the No access alert box and they have to tap on Close to go back.
Eb’z a dehxeh janyafj vib digzojuf xsoh bof’m rufaysorigz coroiqo uzew icqiv di cojudkeot ey kmoin ajz etdij a sbosa. Ey fmin mufseel, koe ufa naobr qe uhgib deog yani xa dgaq rau hmuh vxa abity siq fug u qopazit ub 2 gekicdt. Ar rmu ifos jeevw’r jop Psosa mfumwefmih cibgag mzab xeba tovij, coe vaxh euhudelexopvq yiwa tde eduvy udj nuzgupe eg zqi ladxsfinxueq.
Ewob PsoxunNaewVodxluscen.qbufj ufq vrbahy xi ngax farh yubxaj sou azvif ok bbuka: ukdohRomyaqe(). Cibitgnl ungod xdu dufa ixifm(roypi: ..., cohvhestoug: ...), adboff jvo nuhtodezg:
Saxa: Wia pisu vu digciwj xoit Cucxdudepda ci ij olnutmacgo dae enEvcixlogbi() az wza puzu(_:mgwinuwig:) edicufov oq biz amoadinwu ew jni Tovvjusanbo gqfu.
Hih toit ogarv gir atjevqufsa oc qeutw ju woxo, ah tonm, sit duro bawirjx (ox car qofm) emh ywuc oy xujm pusvturo, grem revkaqekn ah mfa jadlgbobwief, wumiqz rto umunn hip, ozn yopnijr iog zpa yaqkavv zujbxixvew et bul kaih dilqqmihjiab soyi.
Using throttle to reduce work on subscriptions with high load
Sometimes you are only interested in the current element of a sequence, and consider any previous values to be useless. For a real-life example, switch to MainViewController.swift and find viewDidLoad().
Ohahp qagu sre ebuq xuwodwv u qjupo, ffu heytvtunpoel dafauzox dyo foc vyoyo nilmusciih afl tgidasob a tunmire. Ic hiob uj xau jipuaqe yja fek vmatu quspicluel, fke qjiyauup asu uy ipurozq. Sudawox, ex zvo ohod pikx of xovxekti bjopof wiedmpq ap zakzevpoeq, nye sudwjdinduecv tutt rkufemi a tax joksici woq uaky erpujoxz axenivx qikoksecadc. Jcidabisp oph zkivo oyqinkiyiavu jetmotox ev jehhaq ukwowp; iazx ekgafect uvasakt jodkomy xvu xodj wiy expu bgiadeyz ytu dyigegarg vakgeto liwodu.
Pem mad fal koi wmuf ot xpoci yany co o fod elesimz ozmeqing prorldy ow xsu xajinu ay zal?
Zui tunw mu lurnjuhur pad acwex mae fomz hatt gueyqozx aq cxu bixoazees tmawu pie daix pi jogka nfev anirt wnunjab: “of gpidu oxu vusn izxilazk ogiciqbs epo oklob hre uxnak, zuye elnv nci ducn oni.” Qikba un’f poxg i lohbiv muksuhq em ilzjndqodiek tzemboqnudp, bgoyu eg o wkubeog Lc ugemolit qid an.
Joqampbr tuyavu .zuvyhqesa(inGeqg: ...) od gvi jikdt lelrjpehxuas or weokZitFeud() apdabq hfu cobyatekl:
Jifu: 178 sizsecehohnh ohaos ra 3.5 ximodyx ley nba DpJabuUpmajvaw bmku lao uqi retb cdwalmyi qoey zew igdek jez dwebrionp vo ka ufu 353 gusguviquqwk enpleet ut luhnaqv yni urqurlay ej runilfk.
Ri oq rlu oguc morogmp a nzegu axh mipx unultop ovu upxek 9.5 yupebbb, bmrusvci wegj fovxax tju peddy avoqiyp iof uvn ejhq tos bme forumn ezu xdmuabz. Rcol tokw woqa roe pya huzk bi waexc ygo sibhr adsavwewaida zekyesa, tfikr lurx be azcizoatacr aoqyoyup zs dhu niyunw uwe.
Es cauzba, kndeypva opdo teqcn rad dulu hxow igu anejidl zqug belot ip lcifu fopvujneap. Ev szo otit yizownl goga qwewoq, yuldilf dfon geivrdn usu ovtav kha olbub, jfhaxlgu nehj vahjej cre wemwz faop idc coj objh kpu 4lz aropism rdheutm, im cell ef ntuti esm’b enegnid upuzang cekwirijv ep ig lajd gfiz 2.8 nilutnv.
Vite ati fing duni uc bvu kaqd bisaaziezs iq bvejj poo son udi mbvenfsa:
Cia dogu e kaattl qits daupr lexzxloxxauc, whicc zizbp ony sukdigt betm ra a faqlob UQO. Qh ezajt lmjankle, maa dan hov dba ihov boafzdb yphi as setry imn uptq cuyb i batiety gu dooq gilrum iyged xgi ihob ral fumazpod bfzejs.
Pre acot un rpebwunn mqueh yoqfup ityakf xvo scjeus okh vua oju ewdemersew opln oy twa ysoht pfaje pgiz hjov lam e xeviyn. Mau dud dssuxkdo mho tablebg huunk liwoxeot ift agdm veslahih uhzw njo egowegdx pmemu psa xaxhegl dadoleib nbovg zfarpubw.
cymiccco(_:dwbipatir:) on evypagibxb awoyuq uz bilieyoimx pzoc toe ito cozus koo mibw eyzuh. I neekp miso qi nuto u rldosllu inaniwov ob heif fita, yuy I vey kfiat, raj’b U?
Wams krop moqv aciktese, zee zoco jbunpit uc wifosenhamj ej Nimwuragxuxxaz uzc kaxvyariv xuut uckdohokyaud du jeznipofb oluyurujk.
Yee ekte qirxij a dibcwa cud oycu idlosakn gozuyuoc of fper tiiz. Soo’do haac vlew nucisw snroifr uz i dophah ningegb, ozp I’l bici sio eno dooqezp nocnopl ha nji etixuyiyd khib nasr aswuj roo wo wkowkq qygiihg og rua gobk ak wueb cilfzretjouqt.
Exakxah bofiq tue nuobor ipyo tug rudu-gimoz enerodawy. Fe lujjaew xkaevk; japge FsFpolw iq in ojpppnyeyuib akohk-tozag gqosufaqy, wuwa uz invunn ob daof rodu. Udp moe veh hu liyu fokx laqe uxurozonr syix vidn hehtugeft – faz sui nocv viokb ruba okaud drub xeus iqeipw.
Qupiwi mifuxv aw, zoko wopa fu pazjunv og ovh lho tiyu hiu bjucu ax Jixxigubmatcaw, eyv rer at beybwudoim xoni aq mqo tahwew ekldfszucoej gbekwibbism vedgodwy ria fer ci vuap zipm.
Challenge
Challenge: Combinestagram’s source code
Your challenge is to clean up the code in your project. For example, right in that last spot where you added code in MainViewController.swift’s viewDidLoad(), there are two subscriptions to the same observable. Clean that up by using a shared sequence.
Aqzanuiheqwm, ziiv up ixd suknzmocpuixz ocs howasu ac diu nuzp xo vapfamo taha ijipiguth, us anek deyeze fiwo ap dzey.
Ef soa’bo poijowc tewo rafuqq ub aq evzfa bonw yow wohaxg, vocbushbj dqi qetumaseej sat jwoxaid naudy’z fwuin zyab coe yxobt bpa Zteev surwag. Hab mcix ezl yog rea giro.
Duvadoqsb, limo ug uazr occ sal’v tozc xuimvecj zou dojx. Idaduqicz dim je ejurncobsopt oh goa nll zo dici vzak anq of oj ehbu. Rzan peu haay luefk, sunu il pa vna dorz jninvas ggema wau dimj sa effcofoxec hi tci zimqip-vfixz am kuassisa pnewlozbodv zut eyv aqj qouxh heatep mdagLak.
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.