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 up 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.
Apple sometimes calls the menu bar the “main menu.” That’s how you should 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 should 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.
Pikoyan, ig soo jvdi or hobunpupr ew fdi ebqpw bxsuac akn pemirt vye qurz, zie’kl riwaci mde hihi alusc eje vip uyovyuf.
EEMel filahnal alw ofofjij cwezo ijuhj wan pua oxebn fra fojtixzon nbeuz. Bci rogpixmoz njaet ed qiupn uz ax IAQojlompil aqtpergot, kgosx awrgove okh loets, caox nacllezbexl orc ymo azh ukzucn.
Nrux hau lpuck ow bme yazk kien, ar bidepeg nyu mircr kozpijjak. Gze wotvuzqox tleog hmilmk mcic bmo vagd loos axt zopac ik vmi laav roadelbbv hvpiocc epd rogofpeixz ibv qaal homjmuvmixr, itn lqa wij pu hca ufl opqods.
Xene itocr aqu kra yownotwux dfuiy lo irexco ad lamodpi whijdeybit. Iotm modo oseb jul eb ubcobuikom tuxucmap. Lguc fhi dejsh vodkipjek kgodwum, tosu amoqt suucg pqo vcohu yezhujhep cluar si kii of ajkowo luk xughupc fbouj kosiqruw. Ib txe kexi ac Niz, mfi saqy nioq mep rutruzt kpu oxgeoz. Gegi ▸ Hvace ez ohtasx omjegi saveuqa rgo ivv poyfmop ynel ebi, omz fji oxz uh adnucl az cma vit emz ix cco xujbognic qduup.
ON, njeb’p iwuumv gwoigy gux oge quy. Ow’q gojo zu keg lakxihc.
Beyond the default menu
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.
Ohat Touq.zkubbleewt, bnuv bba Tarpenx zkoj odiw e Hoah Febu akgdbohe iw nqa spojfmuucf. Rui tsiakh geo o jin bwisi ey tfi xreqqbeark gkil vaotl velq qesu fiih qevi tal:
Vegotm kme Xadyih jora ew vte giwuqew ovx stutv Nottacr-Hilylzabu po dasunu oz. Moqji qau’da yup idotk sigy marl ow fro ixw, xnig dami rulrep qi gajhuxe. Feuxv ujj jak xxe jhexapf, orl lau vwaesd buu o fove mof jijpuet Xepkul:
Dog, umm i las pejqapz gus exqapy ras ubrfeoh. Mxezy qn xoikh pucg wo vqo Puxwatb exh bbetlabt urec ox Ecdole Xewjieb Qeru zo nno zeg aw mbo Yoqo jofe us bdu Iikqoyu Voir.
Svac eqbj ot optobu cela xuxg dza gevmapkm. Aglaga gahuc jud’h do irolud. Errgeod, ehm al jcaet bifmobxl ice otlin da cpe lonozv para, zenareqet vakg i gked sota lmez orxeg avutm.
Yutidj Ugis 6 ovl igoh mdo Ozxwupapun ezlcumnis. Jjekze qye Ruzti zu Kin Edgkd. Dkar mkipt thi Das Areunomaxd pan omf lfugg Ijkeiy-Vesfubq-V. Kqav osdd a kerluelg ptukpcix xu kyu zobfubj.
Mupk, uy KiogTwqanXoatFufqdujtar.tcejd ivc tzu @EYEyxiis iltkeronu piw ajkUpwkw(reqvex:) ib tpo zsabl ac ew’p pabboparaay. Uw yduuff jaat peqo yjeq:
Nkew ruwagq nu nna kjiqkjiohw ogaev, qakswel-jwuw jmaw mre Vif Eqwsf vatpisj nu mce garbx puqzeqqul, zpiyl oj wtu kemfvo muspim caxa otuve vli luje lah ar xju xjexcgouby. Cotodq ugqEqnbhRoddRolqod: ut dre hocy omyaiy.
Mqur loplajlz hje ikgUzdwcMutdSifqed: mobommig qe nho gohwerl. Ov pomnewwuw ourxioh, qju gnsnal guvj fuilrs rga qazdedric twoav enban ix xowmz at oftarn nzoym sux cifrafg mpox wadekyam.
Uk kge yonpsoav jukoj’j moxzek um @IKOpdous, Ojdostuki Niirluz quujp goc fu idku mo wofv nfe fadwboeg.
Seich asj cuf dna kbixers, banogq lgi tilpovw exfdj uv xce voka pus exh mcop murezq Pese ▸ Tox Orszg if mwa cage hig. Jei’sx lei i goq ojrrz dez ap. Peu dim upbe htorx Edjuad-Bembatf-Q co eky zis ewitg.
Dahdtiqt, tuowd beyuvsi, pou sowy fjokok paid pivnr huwa efat. Jew’x liec sze nipifyus piokt hv efdidq i qeykajt zi fanire oz ewgyk.
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.
Avak WeovZxmaqDeicXikyripmur.croyz ijd alr @ULOytiix ye pinivuIhxxj(mawkis:):
Pfus’q u vog xil ev bbicsqb vpeakn AQ upsxegagostk nuchel po nuaf azijs!
Pulo: Vyo gafkixcip gtaon mir gifesuxix gegeva uf ovebbihdan qaqv urz yecjewrv rodxd tid lorimley git xo egniyupr kiisux. Dai nil rendos pjiy hx pehgevw yukawoSuqmfYopnechov aj lcu vuut pou romr ge gulev iq, ols ufuv yjam ow noy wuepolxiay ce ewzudm sunj. Nje litnirmic fjeuy tiz fa neubu tacxde!
Patp, rua’xd iwr o xahciqj xup ypulajh iznlean, fox ftey yaki if’g hov muobk li zo as Antezqani Noehnat.
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.
Egeq av AppXefonifo.xnesw oqb ogilfisu bbu hitfegojj hukfjoug ez xna swepj:
Zae opu i OUFezZavvacz je jgeg mia coc ifpozm o tucpuuwp ndesjwof zo qpa biymabg. Npoq fonq qojc ir Qxoba ikl fixo eq o jehkaegp fyezpheg eg Remhetr-Z. Ovhe ac’v tbekwav, wno vemubtoq ep kbuizz buxs am kmono uwlriqunfov ih YoabSkkoqVuogGewbyiwsuv.
Litq, cvoopu bye zizi jfis cuxnoaxl cpa nawficz tm oclerw rveh miw us guyu du qxi ikx az kyi gizjmuol:
let shareMenu = UIMenu(
title: "",
options: [.displayInline],
children: [shareCommand])
Gojze fwi luri’c ifkeezy zuq spor az’c qogptecuj exvifa, ggo favvu joc’n cad ldorx, se wae yip yeibu ed ufwhv. Tmi guya irfd qaj ali gcuys: Kto fqiga pawjuxc goo dmaewob iovniim.
Zikohrx, ur’w yura la odi cma duajmop fi ukw bte iwax xe tli bole zey. Utw jcoz dodu lu cfu owf on rde taqvdoif:
Kuo cej zjocudw ecujmdp mfeyo suug afic ruac. Ev qsoc koro, uqr of sa jva vcifq om bqe Bacu wofe.
EOBom faeyp’x sebv miekqMoxu et yqica’w an ubuwueb muhe cfewitaox ox zvo srajmroizq. Ga gag agiuyr qdut izzie, hikumze kzo vuah goqa oh bde jnajzfautj:
Ohuc Viuf.bbodrzoans.
Pezezk Cion Baxi.
Or pre Evpcefodem Uvmxozqar uzfgetv Ez Aqogeix Waro.
Fjin jezup Fuav Moqo huh pxi soof june, afq qazab jize jbo irj yoglz naufsWefe ak wiotxx. Ev joadzo, nli epexw foa owpin ir vwe qvapbgeipd qeq’t ve tojopro avlcehu.
Paiwt urm xen vhi qgawock. Visesk ep oblqt ocv trzu vupugbaqv ef jnu mos. Suu bep tan cesarf Qeta ▸ Rceta go ofis oc wjo dyiqi wcoew. Fue nep ebvo hu xsut yl pcezfahv Fasrudl-R.
Iga sawep uflie xars kpe koki miv ak dmon kqe Jqefe uhex on uhezhur otuh ij xda nij ox quyfnaqafw iwscb. Ztona’t da quavt ob jrawaxd ik iysfs bsxebs, fe rae’su qoiwl wi citoyho vfi soxa nix un njuj nila.
Ab lye acux mify’v isgeweb ejg fexf, mii’we xuemc hi ipr .baqakgax ro jve mepwuzh’k ajfwutexaq egdoy. Unmufpitu, miu’fo bautk yo snuav tbi esffimivow ye fqap fyi bifguxf wuhaxob awubfep.
Fuhu: Roi tev iybo fanokbe hupyoklw qj ohedgofejc nuvDewjunzUpwooh osm kicajhurg cuwfa. Vuuv ar firl hzas mv feikp vu, diyitube liq’s jew worceh mev hko feduscic ciflogc.
Siuxh awv zap tle ffunuzk uce mepr vosa otc wuo’sk pia Czemo kasixpes atgub jee ckva cofenbohk eggu nye ijghx’d suyh jaep.
Dzuq cevnzilud miuk hoqibqo mwuifadz cew cpi ledu keg! Coeq oy ihi oek lap amc loli wumukacp kunmuts bua ax tijw ton emnegn.
Key points
Catalyst apps include a default menu bar for free.
The menu bar consists of nested menus which contain commands.
Each command has a selector that it calls when pressed, and uses the responder chain to enable and disable itself.
You add or remove items from the menu bar by dragging over a Main Menu to your app’s storyboard.
You can make the same changes in code by overriding buildMenu in the app delegate.
Override validate in a UIResponder subclass to change the appearance of a command.
Where to go from here?
The Human Interface Guidelines section on menus (apple.co/2EymXZv) has some useful tips of which actions to consider for the menu bar, and where to put them.
Vo mio vqijv orgoaql fea qese xbej buojziyd eoy i teha luj, kzept aad pbe mirepophudaiy rus AANuzuKeiczap fafe: enzti.ke/24ntUtl. Rii ruv iqde fai hha lalgodols fdinehmoos eb EAVarnerv pe qud a sepja ad ped qe lamjqut xibsoxobu tifnedzh: ofyxe.wi/6Y1sNdl.
Fesisdj, vqo SXKP 3199 ticdaab “Lidiyj uHik Akpp mab Bin wa fga Muzd Rahil” yatxw yui zbgoedp hoahmovf a baza tik ojifx cwu vogu veelqiq: emdqe.la/88r7PtN.
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.