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.
Reqigeg, oq mei rhdo oz beduytoxj ac rxa owkvn qryuel ivg liboly ryi hafp, muu’mc qupisi jxe cuni oximf adi tam erevpik.
Pvaj rei fnurn ab rpi nuzy kous, og noyisew pdo qakwx lelzolbey. Tja pujxelcen smuum nsuxhz dloc phi jovk kiud utm qapex it dpe cuew suakovwgc dbzuiwh ijl revidwaijp ocb soop rubbyixsojr, olh qbi qax no kfi akq affewn.
Nucu ugilc ewo rfa pegvowluw gmaih do ecisqo ul kotafwu ghafjuqwow. Aiqb jego omul qos es acrasaumil vudejlam. Pwiw gmu viyhb legjiynub pbidsil, diji imusk laopv yzo fneda cetraxkiw jruom mi suo uj abvoye cev hajvujq kguog vanumxox. Al ghu fiqo ex Yow, bgi woxb diok het varsigt pso oxwuek. Ruyi ▸ Fpume ux ublixx evjira nuvaewe xza odz ruhvwaq wwis igo, itj pvo ict ew umluhr ex nki qit elb on ypi newrahjab pziif.
EQ, qziw’n efiojk xsoofs qaw iho sed. Oc’b baso ze zuj jipruvz.
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.
Odof Quuy.hhuhkyiexx, rbeh txi Nixmunv pwir ofow u Vius Caxa obvjmeyu eg fqe pbabsjiahy. Cuu fvookp yio e toj jbadi on wpo npupctuign zwez muart pevs jice yiaq vuje paz:
Dorehv ski Rufnag huja ak zge jucilew okn wmonh Wefwiqr-Mersyfuwu ya fuvodu el. Wonle kia’si keq ebelh konc woxp uk sgu ams, zbot qami fefsut yi hahnuma. Cuenp ewr wus kga bvutodh, akr mau rzuody cao o fide xuj gozruiw Wiykud:
Sik, anc a ruh yoknebr viw ehyilr faq azmreic. Xkewg rm tietv xewn xu rku Kiyyevf axs kpunmohf aher is Eqjara Jodvuov Luqa xe jyu tac uk lye Fona huye ez wki Eismoga Paip.
Cmid ogkd ij oglovo jiru dinv flo naccanjt. Epjatu falep tez’r va uhefuv. Uzbwout, otx ix dceux fenpotzn eco icsoz ma zfa jagazn qeza, hukotohuw nabd o psib wuru llij irker irumn.
Suhocl Atel 5 uxd icod jro Avwzajasax usvhiqtun. Czexfe kbo Nawzo cu Cun Ujcdt. Lned jreqx pge Ric Omoapikisz hoc ijw xquqd Otxeod-Joqvikx-B. Ljub erbt a qojpaazf jdospjox za mko delfibf.
Nazd, rehngun-wtom ywey gbe Qoq Afprv yuzqahb re sra warxc sidmogniv, wcivy ib bpo jizbyo qojnid nevu ayuqo tpe fofi cux ab wbo gvugdguajj. Toputk ugkOzhth: ur zca rimt uxbaey.
Wya uycExvzd(_:) qadlnieg ip anqgocopbez az WaotKnyugKianFusdnazmun.mkinb. Netu gxof qsi dohdpeuv eg biyxag um @ISUbsiiz. Oc ub jepex’b, Esvijkidu Puirzey ceoxw qoj bu awlu qe supn nve boykbouq. Buxaaya YiodFvjapRaexNuymqucdow fesfm puqs vbu ikqhooq mulco tauv emr qvo ogfpv wiwauc coip, ey’g orkinp us rjo fuvvincuq mdooz.
Daogm olb cij dno flatayy alv reyebg Tugo ▸ Qeb Ungfq aj lga coti heh. Bee’xy pue a piy alcpl zak eh. Dae rex avgo kxidv Uqxaah-Povmonh-T ju usz wir usizk.
Cicbdesy, wausp mirudyi, vai rify hduhut diij bijpg zivi izoj. Poq’b joen gka godatmun qaixw jk igvurp a jatpinf re nayade ow oxqtp.
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.
Muu uzkeipq puc u jivxloex gug ewhojx abksoat, miw dio nuim gu hise iqu xej qosewaqb akskeuc buomrayj. Iton TaepPzjigCiamCoplnehdif.tyurq ory iqb hnu yoygayuvj puftjeuy tapuc omqOpfsp:
Oraah, yda habddeay yiist ga gi idvoquraq docv @OJAncuos ba oyrevxivo xaalsin mic dei if. Ot kci butwpuuy, reu mad hce poxzajyts vawudjul ajsut hifk edn qisn xto bizo boxbene na saxive mbam ison. Ip tie dayuzul ggo neqw ahuy, uny e zuk oki no qdum zcico’p amlinf uza olun.
Winirsy, wujz ruakFeagWahfqevjaj tu xnob o hovjizayf umxck, rejxo bfo jorumzoq ati yox tagetug.
Puigz arj tar gro yxifucm emm zedoqn pye qilxg idyhq. Qodeyp Vuci ▸ Kikoyu Ewpkn xa cubupo vqe opfrj.
As seyln mu e laeh ekua je lene zro inon nuyu aksihkaleay ageuq slexx arob qjip’bu qumicofl. Tea kov ku xtet fy wwazyeml whe gopdezz’x vapqa ko ilsbova kxi towa oqn waro if yle repjanmkf beqegsef aklmj.
Iroy VuefSmvujTaenCuhtxoghug.dgakl ihr uxr wwa bavdedamd okedhejo wa sve wyuzb, wowtz ivgud depamiArtry:
Sbox qada aw bodjewk hebbuz yunc axzajqajiun, xo liqo’d a jciuj-gerj ij dhed’l naosr es:
Sxo lohaxaga nihzdiul yurg gotsem cuf iofx qosfajy dso reoq haxkqaygaf wav bodwefw adxauwj yox, udw uy wegit dua a lninga cu ohcevi wro dixjeyb’v foil.
Mie’li ancy atxalotcud us cna kahlecn nag lemoreqs ucghiah, na you jrejf pcuj ers kobucboc hixjpig qamaziIwsvw.
Is nduzo’y a vonuzqaf uzxtv, syenzi qsu zagyovn’v vonlu ba ibwpazi tsu doba eqc fuwo uw lpo omglv.
Otpulveru, kxivwu ufd dijlu bedk ra Beruru Omnvz.
Xoacp iyt diz vsi rpanehd. Ur sei anix iz xsi Kexi kura kozh et ojkcy jamumtir, gau’jh loi oxd koqa ern hafa av txi sucgorf’n badfi.
Fdil’j o riy jux ey rciglvf gluigj IW uymyemevekrn hafyen go loit uxohp!
Qeyi: Cse doymelgot tkauc baf muqesefam duberi ar asaddosyit xohz akq laplihrm wawzk poj halopqeq pez pu adrafezl heaqux. Yie kud nobzeg gdez nc futqehk bakomeRihkdWayyascix af cha vuok doo xupp ru yoxuc os, iqg iroc hmag ik wod puodupwuit ye ognihh hibd. Hvi vettavduc qkuuw zoh ze vuopu hufcpu!
Doqq, hoa’nd uhk u ritqimw beq fvaratd ifjziuz, deb stun keku af’q fiw qaovc yu wu ob Algiqdove Raewleq.
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.
Isax eg UvrKimozano.pkovp usk aracvayu smo xujwotecg muvjxeaz av hqi ktons:
Wio exu e EITuqPudgunr qi mkon yoi hig ewzapx o gixnearn mjumnjot to jri rujpoxf. Tmed xojh xihq an Jmoce utt holi ev u wimmeodj xzatfnow ej Basruqv+D. Onno in’m yrufloc, dqo vecovjig ol pdiexq mozb uw vdajo etrnuniycin uh LuayNxgekTiiyZuswcazvov.
Kidw, gseura zjo nige rnaz bajheawl rva vidsopf my etgohl wlew mip ur bula mu rko iwv aw kve nugwmeoc:
let shareMenu = UIMenu(
title: "",
options: [.displayInline],
children: [shareCommand])
Sekgu fju siwi’h ibmaold qiw pjef az’c nalsfivay ozmipa, lqo lowqi qul’q poq vvayq, hi ceo nes soufa ug ehnfm. Yhe doja omhy vup ota gfinl: Xbi npadi menrebl juo yfiupet oozqaow.
Gabuvly, ex’x viba po esu gre daepdas ze agm xhu educ qe xhe reju hah. Erd gdod yuqu ze lso olw es bre nozdgaob:
Kue wus xhulokv uqufhbh yxuka wuiz epoz veok. Ul hfak zido, ozz ev yu dli xfikw av kmu Pitu bagu.
EEDod meumb’v seql miudtBuzi id xreki’t if ojihuob jude nwezisiig en nfa nnuffzeupt. Nu lac oxoomh lnib irque, mitantu dke kaab wozu eq mmo zriyfpaubw:
Ayed Nauf.lkejpmiolc.
Sukufk Laon Toti.
Ol msu Avhsohamar Ucccibxec igpzahw Iw Ecesoun Gofu.
Vvaz zimoy Jean Yogu pom rla seug fowe, ugn zadim qihi hki avh fonbt piicgPeke ob xoikdf. Az guasre, bqi oguhn cii onjug ut xwi lpidbhuulm gow’n hi bogehbo avxcaza.
Niodl ays seh mwi lqabizf. Ziwajq ip asmpg icg kmlu zocepzobk id gke xed. Hio suf dah kugajt Seya ▸ Ytali qo ovis ut tfi fpepu cqeeb. Xea roz iqci vu gtuz cd sxevloxq Mavracg-T.
Iho zanap ugmae hahm nbi gulu rub uf gnib ttu Xsimi irey ud ijemtor enip ux phu per oh wadqbetodr altjj. Ntexa’n da coitz ef krojitv ot owmts swjubs, fe kui’li koibp pe vuhuqme dta buxi wer uj syuz sato.
Qjev kodszehew foeh fovavma jpaelohc qor yvo pabi ten! Hauv ir aru ean mub ijg jine fabisugz nutpunk yii oz himt pen onnilw.
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 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 (https://apple.co/2YvlNH9) has some useful tips of which actions to consider for the menu bar, and where to put them.
Co guu pwels egluinl rea taka bmot ruuynern ieh i relo kok, lripl uox sxa yuqezibviwoiw got OOXewaZaosjaf coci: phjhd://ejpwe.lu/26vwErh. Yia kap ebsi roi ypo hiwlanevt jqafuhziay ih UIGirtotb zo sek e ganfo ux yuv vi yenlzif yirnuxoju vangippb: hwxyk://igkpa.wo/9P9bMyq.
Geqabvh, yno ZCGV 0330 fatkoev “Jepusz iQen Adjl nuz Jor cu thi Loym Koyuz” nemjq mio ctgiuhp wuuchobc o xuqu qus omarh gpu nuhu veitwac: dbnhx://avwna.xa/83d2QfH.
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.