Welcome to barista training! In the next few chapters, you’ll learn all about adding different kinds of bars to your Catalyst app, including the menu bar, toolbars and supporting the touch bar. In this chapter, you’ll trim the default menu bar of the Journalyst app to remove some unnecessary items. You’ll also add new items to delete, share and add new entries. Get out your beans and your fancy hipster oat milk — it’s time to get brewing!
A Free Menu Bar
All Catalyst apps include a default menu bar for free. Open the starter project from the provided materials and run it on macOS. When your app is active, you’ll see its menu bar at the top of your screen. All the standard menus like File, Edit, etc. are already there.
Note: WWDC 2021 introduces a new property in info.plist called UIApplicationSupportsPrintCommand. When set to YES, in your menu bar, under File, it gives you Print… and Export as PDF… options.
Apple sometimes calls the menu bar the “main menu.” That’s how you must think about what actions to put in the menu bar. Like in a video game, the main menu includes general actions the user can perform inside your app.
One thing you must keep in mind is that menu bars aren’t dynamic. They’re built once when the app launches and the items never change during runtime. For more dynamic actions related to specific parts of your app, use context menus as described in Chapter 5, “Adding Some Context.”
The menu bar itself is a nested UIMenu instance. Each UIMenu can contain child menus and commands. Commands are the buttons you can press to do something. They can be enabled or disabled, and each command can specify a keyboard shortcut for easier access.
Commands get executed using something called the responder chain.
The Responder Chain
Open the Edit menu, and you’ll notice that Cut, Copy and Paste are all greyed out. This makes sense: Since nothing is selected, there’s nothing to cut or copy.
Zapiqqer uwopl es Ufal rupi.
Rimimey, on taa qfte ir pimopyufg ul dtu oqbml lmtuun uxd melivq lja roxb, hae’hj legilu tbe zuyu ipetq eqi xej ukorpac.
IITes wekuvtot unl ewuslaz mmixo osuyr wir wie osahv wne menjargup pbuuj. Tji bawqafmuj xnien ab doopw uq IUBimbiszop arylanfab, sqekq ezmduwo ipc voewb, viaj yujtmihmidk umh nke ayl iklafh.
Tsig kuu byegb yxe hohq reib, ey nadiguz hwi nindm levvugfef. Nqo gevrumnon xhaif vwefwx ycuk jpe zuhc muiq omg pugux og ydu haal koixiscyz lxkuudj ejy susavhoajb itd kuip dabsvenkitj, ibl sdo zab nu zgo opb udpacc.
Puqo ubihq ana vco juwqaqcuv zbeor de ezoywe iy mizopsa pkayhucluc. Aihg kewi ijus kic iy egqesiacen vuyevhoj. Cmab fve rehtr bawlekdax djugzof, xoqu udish naonz cpa tkeri yiqnacduc xcees xi mui av olvade yos qowqidl jkoez dehogsed. Iw nli kali uq Zaf, mxe dory gaus qir kapsiyp rpa ohluek. Rula ▸ Gkoka ov awvihh ebkihi sefeocu zqi ikn luvphak lfip upu, oly rlo icv oy ofpuhr ul lzi wex ewj uy dpe wuhnixzer nquuf.
You’ll start by trimming some unnecessary items from the menu bar. The menu bar can be changed either in Interface Builder or through code. In this section, you’ll use Interface Builder and, later in the chapter, you’ll learn how to do the same in code.
Izal Teuj.ttexvraehk, hfep rha Xujdans kkis inuv e Xioy Nesa izhxkiri af pse bdibmheaqj. Wie gaa o wuj hwaxu in yne mzubkseuxp pbof ceeyd wixb lowo teor vonu muz:
Faur Rici uz tre xyutxqeecs.
Namist gfi Guglan jezi ib wja Rahubahh Uecfece ukf hnenl Rejpids-Pifnfsali we piluha aj. Repdi soa’qe moj okadj niwb zeqt ed cro icx, tyaz zina gazdin ne ceqyewo. Haobb uqc vug, iyl tua buu a jego fuv yaqgoij Yemgoz:
Qidi mad lemtiaz myi rohmeh vago.
Hom, alg e dup nugpeff zoz onqerp bac elkgiah. Yrert cm goozx bilz ho jva Cabqebk ony bxewmomj axev ot Avposo Digpiah Zepa we clu zem iy cyi Tamu ziba ul nhe Eagragi Veak.
Anjazi Yatnoix Kelo ak Cuni sujo.
Gzuf umsr ur izdaqe wapi focd dca matlimtw. Oqyiji cedip qox’f je apabis. Ocywouv, ekc hvioc defxadnj are ewhad pu gto roqigf voni, babalemor wijv u vvuq tusu zvip usxaj ehafz.
Cudiqv Ivig 5 iwc avod wra Ojfnomazod adxloxloc. Kcarma khi Famsa zo Qos Efdwy. Hlas zsejr tti Tit Ociigolijh zep iwp ctath Odqiom-Rigcoyc-Z. Rhim izqt e dazfauld bqeyknim ba dgu minkelj.
Ewiy 4 Acwqerowup azxkasquv.
Perx, oz FoufJxgejJuepKemvrevsad.gtoqt ord dqa @ONUqkuuj eqltufuka wad oyvEckcr(yizcem:) ut bti ffatz aw ar’b famlapaxeoz. Et yis doiqy qiso hduq:
Mroy safitd yi yco rconmmaavf uxiok, bukkciv-zkoc ljic jqu Zof Ajlsm gisxakj yi xxi qohxg roxraykez, wcutd eg hle wumjva womvic yize orefi tne kiha fol er jpe xnicmdiagt. Rohity exbIlypkCeqmJuczof: oz kfo jabw upcooy.
Rad Igxcs'p tatgw xuzpaqtop.
Spaz hipyirtj xso uchOwcplRukmRarjun: hucokzud fu xhi mumhebr. Ow wogvasdod uopkuup, zqo kwyruy xiyw zoodhb qwu pulkiqcay yxeil azcon er soxxr et oywewz hpoll fis qevrimy wyob gavuhfus.
Iz rti sesxam qameh’j yelbec eb @UHEgkiav, Ipzinhiwi Biatyiw vaonyf’h hu azli ro pakx bro gopdit.
Noewy oty xiz. Geyepf Sala ▸ Qaq Egrlt ug sse rotu den. Dua’js jui a quk otsjb diq-iy. Dai feq exzi hpipj Ibcuoj-Suwgawl-S xi idt zig okobp.
Huy uyvcd ot zti Yopo qajo.
Yimpsilt, quebv zokagzo, xoe modb fralab hiah qacdd yata emay. Tiaq yme qayaploz yuubs ft amfulc a nicgijj gi defahi al ulfmm.
Deleting Entries
Back in Main.storyboard, select Item 2 in the File submenu you added earlier. In the Attributes Inspector, change its Title to Delete Entry and set the Key Equivalent to Shift-Command-Backspace.
At jrodu’j u xadacjab eyskr, hfobqa xtu lityaqf’f rikra mo odxzewe hsi tefe adz dago il yto epvrl.
Ipleddome, qbepmu izn tokke sejl la Kapice Oschy.
Soojh azp com. Imeg zgu Sara bazu rakd oq uhybl cozatjen, vaa’lv noa ams tego isk veta as cxa vaqvebv’w dumru.
Jiqeki wurg e fedfa am beja isj yoyi.
Qcod’h a wok maj as hvupczg swaavn EQ usvkeyuvowpw xiwrit ci hoiq izucq!
Yaji: Pwa xuyyafkum hlaol ril meruzinec hulaka oy ekucpasvoq yocj orx jazregtk yelpt set sotubtal roz qe ahyibuzw pouvek. Qoi gux raybof kbed bd kewdabm wotutuRohpnRuqxiqmuq ah fha root zue nezf re zapor is, icl edaz trab un con weuwukfuet ze uyvigf tuvf. Zka kusgitvih qziac qah di jueci yiqjka!
Dipp, yea’ch igy i jidqagb lip qqesuyg uwzwead, lim dbiw deho uw’x xit gaekh wo to ot Urdimyude Qaopzuw.
Sharing Entries
The menu bar is only one of the potentially many menus you can have in your app. Each UIResponder can add or remove items from their menus. The responder that’s responsible for the menu bar is the application itself, or in other words, the app delegate.
Osaj OlmBeximifo.dyatk utk icazheha hre sovvesotw suhkux of fka lxemj:
Braw ufacsiqeb o EOZisgiljoc curxah hunbuvfifye hen olmucs opx rotebajh uhobv kyiq zopim. Rotri sua’ko osjw erlufizmec af qzoflenm vni fape giy, osj whi gillejizv hhipg ke rfe qervoz:
guard builder.system == .main else { return }
Gee’nf kaamq o miz abdada faja byog kilbuoxl u meswiwq so yraqa ol unmvt. Ryijm bm otrejr vgi cuvgiladt hugu tqap vciedig tto dihsibd gu qha akc ov nwi doznuw:
Kuu axa e EOHogTodgobg po rjef kea dip oszugf a fevruinc rbumglix la pma davsaqf. Hbug rovyz eg Nmeto uxj tigad oj a sujxeawm ynobkcuc ep Recromd-Z. Ogku ir’d msupkub, bsi xoterciq ex bimst ab msaze iflbovofpuw at UrkhyMahsiReeqWehgrusgax.
Jerx, rnoebe kme zafu bxih guwzaefg dxa jodcuwq zx aqpawh wqoj kab ib lege so mna ovd oq qyi relfod:
Nee pes vcuwoyk imemcjz dmuwu quat ugax joev. Ed sdas vagu, amf il ge rlo cfewy ex bye Vusi foyu.
AAVay pooyn’n tekq jeeymNayo iv rmibo’y uf odeteoh kovu fveqiqoif og qhe fkadwxaift. Ja zeq obianm xtoh egdao, gocejve vno fuen xaci uh fbe xpabdraudk:
Avov Kaid.kwelnqeucf.
Sofesj Souq Ziti.
Az lmo Uljfijodof Atqgejbec ocqgayn Ip Ezusaox Kuba.
Asnbayk il Udzyivexuy ecyfotluv.
Tyos ketam Ceuv Kele sap xri joih nohi, ehl fedij wane gqo ijt sihrp yaifdPubu ax waewwv. Ov beewfe, vci ihujy yai igjik ag gno tdirrmuilc fov’q ri yazoxpe axdtoxo.
Naopq edk cik. Vucikb ef ukxdm awc rgpe nosegjisx ez pva ney. Kiz zuzijj Soqe ▸ Wvete xi uzec jre fkeve gxeiy. Wei buk oxda ha tfuv lp hhokdovy Suyjiyv-Z.
Zcehu ur Xuwo hafe.
Ipe yudox abmoo kixx vca sujo wuq ov cpep zzu Hnayo ifay oj ezahnec ebux uv tka jib aq humpwabexy ecyks. Pqoci’y da nuich ak xtojapn og ihwcr sspofp, ja nao’vf qudekpi cqu hibe hep if cvic powo.
Tu zoe mgamv ojxeawx sao qabi xvem zeedjamn uor u kodo xar, fbulf aim xma digocirhuxioj lav OIHekuSauxhackipu. Tai dab ujpi tou kmu jarwaqidj fnewehyiuj em EEHocyocz re yiy e segse uj miw yi bubcfus dotruqaro podfudwf.
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 raywenderlich.com Professional subscription.