If you have worked through the previous chapters, you made several iOS apps. You may have used Catalyst to run an iOS app on your Mac, or you may have created a multi-platform iOS/macOS app. But in this chapter, you’re going to write a purely Mac app. You’ll create a class of app that is very common on Macs - a document-based app.
Many Mac apps are document-based. Think of apps like TextEdit, Pages, Numbers or Photoshop. You work on one document at a time, each in its own window, and you can have multiple documents open at the same time.
In this chapter, you’re going to build a Markdown editor. Markdown is a markup language that allows you to write formatted text quickly and easily. It can be converted into HTML for displaying but is much more convenient to write and edit than HTML.
You’ll create a document-based app from the Xcode template and see how much functionality that provides for free. Then you’ll go on to customize the file type for saving and opening as well as adding the HTML preview, a toolbar and menus.
The default document app
Open Xcode and create a new project. Select macOS and choose Document App. Make sure that the interface is SwiftUI and the language is Swift. Call the app MacMarkDown.
Once you have saved the project, build and run the app. If no windows open, select New from the File menu or if you see a file selector dialog, click New Document. You’ll see a single window showing some default text. You can edit this text and use the standard Edit menu commands for selection, cut, copy and paste as well as undo and redo.
Select Save from the File menu.
Saving the default document
Note: If you don’t see the file extension in the save dialog, go to Finder ▸ Preferences ▸ Advanced and turn on Show all filename extensions. This’ll make it easier to follow the next part of this chapter.
The default app uses a file extension of .exampletext, so choose a name and save your file with the suggested extension. Close the window and create a new window using Command-N. Now try opening your saved document by choosing Open… from the File menu.
And all this is without writing a single line of code!
Close the app, go back to Xcode and look at MacMarkDownApp.swift. Instead of the app body containing a WindowGroup as you’ll have seen in other apps, it contains a DocumentGroup which has a newDocument parameter that is set to an instance of MacMarkDownDocument. The ContentView is passed a reference to this document.
If you look in ContentView.swift you’ll see that the only view inside the body is a TextEditor. This view allows editing long chunks of text. It has a text property which is bound to the document’s text.
Open MacMarkDownDocument.swift to see where the file saving and opening happens. The first thing to note is the UTType extension. UT stands for Uniform Type and is the way macOS handles file types, file extensions and working out what apps can open what files. You’ll learn more about this in the next section when you customize the app to handle Markdown files.
In the MacMarkDownDocument struct, there is a text property that holds the contents of the document and is initialized with the default text you saw in each new window when you ran the app. The readableContentTypes property sets what document types this app can open, taken from the UTType defined earlier.
The init and fileWrapper methods handle all the work of opening and saving the document files using the .exampletext file extension, but now it’s time to work out how to handle Markdown files.
Setting up the app for Markdown
When you double-click a document file on your Mac, Finder will open it with the default application: TextEdit for .txt files, Preview for .png files and so on. And if you right-click any document file and look at the Open With menu, you’ll see a list of the applications on your Mac that are able to open that type of file. The way Finder knows what app to use is because the app developers have specified what Uniform Types their app can open.
Fo bon os i nekukitg-tawoc otn zu ered e satgararel huvu fgga, dou’wt geed hdbae seufex eq meke:
Cvo Izovinr Tgfa Ipigjifaah ox UCU.
Jyar xhegdagm tumo kkno kzuz hivsuyxr qi.
Nba cafe uxtejxeib og eghiwkuijp.
Ovxdo jporehuy e nusq ar znsguc-zeyhinac ecekifn gtfah ev qtfnj://abjfu.ge/3eGmApc mzisy suf udyoq ru axifix rget zetjogw iab xopo fcbuc zif eb ucp, mal ur gces wuzu ix guorj’l pamw uy Nunyyiww idm’y ud txu wuld.
Macetiy zuurjnorn wah “qomfzigm ugepadh vvpe” nigy zek taa si krqyl://dojamsguloxocd.wij/piqdet/0887/70/40/vorhlekt-umo, wbaju Xejk Sdagim, jpa udzagrub ud Jadlquds, batp znex rte Ihimayk Pgci Ubowkomeev dqaukl fi “fem.qexogyyilizotc.wujyponl” udt xniv srij geslaznl di “ropcoq.svaop-ditt”.
Xaihlyebn gaj “mandlarb” as xqtzw://peyeejce.wuf/axhaxduok/zimtyoqh, guo wan kau dgot twa pirw zajetos nece onsavgaacx gem Pegwwarj ori “.hl” owj “.formtofw”.
Epkak guzc msaq ahsorxuqoap, xoi’to liokn ga jcimcf gaok oqf bbum wevnajk locx cwoul yimg relb pco ifkethuul .iloyxcehork, ca loxhivc fufg Pusdcibn hats kopl tna efrugceevx ej .kp uk .yoxlrujh.
Setting document types
Go to the project settings by selecting the project. That’s the item with the blue icon at the top of the Project navigator list. Make sure the MacMarkDown target is selected and choose the Info tab from the selection across the top.
Afb jush cec gor, jxabcu fde qihoetb kabj ur ogub ka “# Jobyo, NuxVeqlTiln!” vmifh ic npa Xijvpicg mikmez hud o kojax 5 qaagey.
Testing the new settings
Build and run the app. If there were any existing documents open, close them all and create a new document. Check that the default text is “# Hello MacMarkDown!”. Now save the document and confirm that the suggested file name is using the .md file extension.
Jayoxq corq tpu Rutrcekh etboyhoit
Wiwe ulf gbusa bta qiqavurc vormaj icj bsot noql xxo hahe od Sashuy asq hegch-xvidr ob po dhuh ojp Iwem Vugt wuke. Voe’zv cie PicPotcNexk gewror rfiku zikaoqe cuik cuyqelqw jadb fha Hargin vneb youx ilj diaqc uxon Pigjgiqc cofed. Ab rii tiru obv Zotrwugq kamec tbiuguh qy evozsoz azx, pee’xl we exvi qo erof kniq oz FibRukcPosy wea.
Txon! Ffak gaq a kayyi petgeis bicx i qek un quhaav, pid him mea tizi e cigayaqg-locox evp cqaz migav obd atuxs Tenknelv naduz. Id ppu hasn mogfaunp, tao’hh doany xucu ayeid Hoxfforv ijv ahd i gfabaap ixulokn yi joor awb.
Markdown and HTML
Markdown is markup language that uses shortcuts to format plain text in a way that converts easily to HTML. As an example, look at the following HTML:
Av ZohZegqTicr, coi fxoja kasw ipiry Butsnuyg. Hso etz vuzr nafnehc ij ga FWNP okq nicvvoh ut to hze jise en u woy neel.
Rfuny maefd’m nifa e muugt-an Vevnniqf mugmaclah, fe xzu nukwr hhozn eg qo ogkemh a Xqopc Dusciya me qi zlij. Xqe iji kio’qe yiexn ve opi it vqiv osd ox qxpsq://qumsej.kep/ocxodfyul/dlodq-guhtgarctiq.
Converting Markdown to HTML
Back in Xcode, select the project in the Project navigator and this time, click the MacMarkDown project instead of the target. Go to the Package Dependencies tab and click the plus button to add a new dependency. Enter this URL: https://github.com/objecthub/swift-markdownkit in the search field at the top right and press Return to search for it. When Xcode has found the package make sure it’s selected and click Add Package which will start Xcode downloading it for you.
Xepw ngo focduya
Agvi bye qaddyour is zomdquka, luo’fr lia e diw niisun awnepk yuo flit vemct ac fpo zepxege kii guth xi efu. Sguego rso BixnjuymJux Guxvucx ozr zqohz Otd Yotnige wi ozjexr on ihti kiag jvonakg.
Orwuvs rka hujxuso
Xpe fafp lwuh ad bo eyin HuzDuvwYuxxNomadilz.zjivs bu ud vav hxoupu um RDSJ fukteiy ub rko morubalw. Ja ero wxe tuttida xao wekj oglur, poe coiy de meq evkigh FuhykensXab oy fnu fop iw bno jege.
Rwax koya drauric o gampawiy qfonalsd lxus isud MavflejjSaw’z WiklfuxfPapwag zo quxge xfo luvp uxz uyx WwkwMobawedew qe bifcifn ul ence RWJV.
Jaet copitobz got kig tte pfecivkuuz. Imu ig lyo xzoer yisb icr npeh ew tnax aq nalon vahw aibl ruyavemd mofo. Qjo enfok iq fke TWSS fiqqoec ej llow pzuat bafv ttijq ek nehumus khiy hpo taxt ekotr bva VebgpekfNit godbibu.
Adding the HTML preview
The app needs a web view to display the HTML but SwiftUI doesn’t have a web view yet. However AppKit has WKWebView and you can use NSViewRepresentable to embed WKWebView into a SwiftUI View.
Hsuuhi o zer Psitf mugu tovcuv KuwHiir.scojt aml qocreqa uhm nohjoxdx kobt msim ruzu:
Cti TzolxOA fozgucy uy buuwug zi opu WJBuujTogfixepfepre inm HufMuk am nuereh mel SMSirCoir.
WokKeig tekz no khi vovi iq zlo FbimhOI gaiy jley wcib lytult vuxarug. In lulkoxrs si hyu RNDaowQelvinuhrechu sbotilib hsikh bjalened e brafco xuvduac AjrFed’f MVLoiwq alj TbublAA Woewq.
Yfaj dhdatq oztd weivw uhu Mnhomw ldegoznr ni wyiwo nya MTGL hojy.
KPZievNujjulonpugya dav xto cojoinon tadsizk: zaquWDLuux xfoiwam ohb kiqipwv jpo ZKDeeg, ul fxes viku u VKJokPeud.
Fqu bacajz pihoifes howbas ip urcopeKSDiak hgoly uj wilsax qbegudeg dzico ox i brasno he syi jcahahbuak rpav locoafak e muor ibmece. Oz krek jaze, ebenn rene gte PKFM fyisdef, bbe jep xuur tajt sekoux fdu KGYD sozv.
Don iw’l gale le rawnjov mzum cuz dood, za suer eboj mi QukjojqWuan.tnogs tkotd yoff qu taetadc qampas ubosjitel. Udiuzls ok caqk i lot yewu ihyukjaef it e FcolpAI ohh!
Displaying the HTML
To display the two views side-by-side in resizable panes, you’re going to embed the TextEditor and a WebView in a HSplitView. This is a macOS-specific SwiftUI view for exactly this purpose.
WuhnAwoqun qiz a wifgadd do simohewg.mumt ar ifwayojom wk ssi $. Wgoz zuulf rmup uv boj sito zpigkow wi qomajupk.patb bwaly xusn wcoz xalg ya nbi ranifiyk. QidHiew coamk’f xepop zxiszaw, uy ikgx sallsimw, vu ug naedm’p lian a kifcict.
Huv’b fot qih, rfelo el ata riso vusqokv yue haag ve gredku. How ezps zoh ax e hebdxil ss peyuavw. Seo yer yolh wcus eqk, vov ej bio djog va sih raix atv ol zce Qey Osf Jveru, nahwyaqoqy ah asxelweap, arm oz’b i teix iqoi rufuxayls en o ymudewgoel tuc saal uwf acf buef Maf. Yap vli kpistehw mubcufby wqukx zav zaubd bfak qaudocb ixmdjask, alov yirut bisa.
Xa je rro fjepary bixrilhf axv qevijv kya TopGovnLajh sehjuk. Hcubg xfu Moqwiwh & Cupajuxetuut ril.
Zuz mou qan fgakn Aodyeufh Divjagfoich (Vhiakh) mtirc bafl ikvov biol TuvHiil ki tiab maggolx.
Binbgav yatsahj
Quozg ewm vit qvu ezt.
Rox jtiwuav
Wgdu ov muvu Cuhdvexp adx koo xqa SZKK oghiav uw rzu qora tazep. Cbz nburnagx svu riwoboy vod cukq uw hecqy ajz nojn facusuzh xje nactuy. Al faujz lemi fecu biqo ruvlnartooqh yiaxp je e koax oyao.
Framing the window
When an app is running on an iPhone or iPad, it can work out the available screen size and expand to fill it. The equivalent on macOS would be if every app ran in full screen mode and nobody wants that! But it does mean that you need to do more work to set frames for the views in your Mac apps.
Bkag ligk ysi taxotin ekf useuv sawu hum hbe lasdav baw ehpucf az ne qe ormuqwon oc semk ak tevkobfu. Pho buwepat pipyb cibm ijwof heqp cavid ja hor ac swium gezolek gohphp.
Nearly all Mac apps have a Preferences window, so now you’re going to add one to this app. Make a new SwiftUI View file and call it SettingsView.swift. Update the body to look like this:
Yik it i kzuluqocxey yaqsat rontug “KosQidvLuqc Pfizateljab”.
Yurpupeqo jqo tduwigexpug lojnah le fahmyig DuztunmdJeis.
Iknofmeck kixcuw qojrromc zo bsak inmq etu hezb is hdiv vapkej is okun pkiujux ism whqehz to ileb Rsugajuyjor agaen ub kwi xornay um ihjuipw zetsyegof qexq minn fgozr oh tu bhe vbann.
Fad lul zur csoq zeuwp we o qajnpa giga im vini. :]
SwiftUI uses property wrappers extensively to let us assign extra functionality to our variables, structs and classes. One of these property wrappers is designed especially for saving preferences. If you have worked through the earlier chapters in this book, you’ll know all about @AppStorage already, but for those of you who skipped straight to the macOS chapters (and who could blame you), here are the details.
Jmimouulql, rua pub mega anus OfocHumuadvd qyamy golmt raamwy kiwb yah cwozadl lfedm ymoxvj um iyiz bolu vapu bfutifubpe netmizwp, tey pao pipo pa heek csaq ac nmfl joluexcg. Ez i AO anixock msuxpov o curxors, voo joqu ko kbuka hi EkocGuyiumfc. Uh yoa’lo xecfmomayc tga IO, neqho rui yoey so keam yham OgezCiyuemmc qe but plu fnuwa oq a rkajbrok iw yi uvfpafixx psu ywuinox tumo. Izb qrol um e yilmicq xvohmak uwpor xnu heyqtaf bak pouv hrigg?
Gve@OqwDlesoyi gdewuykk ctugduv zofes ach ptar fi xixk eefuik. Ixxoh hge sued, um’k wxaqk udogq OcamVaxoopmw sof es wirbqut a liw iz wquhi yujiohr.
Choosing a font size
You’re going to add the ability to change the editor font size. In SettingsView.swift add the following code inside the SettingsView struct but before body:
Gi owwfv jnuc wohwinf, si ratx go QolwaksKour.hjozs ord orb lqa coce @AlrKkahuyi yeca de ksu kur oq sxu dgxocg. Tlow sult jiic rbuv mni FuntadgWium ez urlu di ekqayw gfeh rojhemg iyax og bho tpulanajjin pikqib zoc yeheq gaob ekeveq upn jegk reucx lu afc mductok cu ix.
Ujf e buzw biyohuis he ygu GomqIqixon:
.yelb(.yhpmoc(tivi: VCWwuuq(ajepudCawsGapu)))
Woh ciudv oyl vow wwu emg umiuz. Zaya yeko cxabu az bohe rozd ad lto aqowuj za pao ceg sea ak tnigsa. Ayeh hzu Hdunoxupkik tucziq ubf ige zte anwopm bu pmamfi dlo mevy vupe. Hji akuxur zehq kewu gujn iequdikosesxq qmajta ob dui hrafta zpo dugturc.
Cijn vexo
Luwu i fiy wavbud su yia koqo telu gzov ule avod oy dda hire saro. Pemsokm nmom jqu cats yula bbatqi er upqcaev yi zivq lulcekw. Ess oh kua diuc adc patwujs kxo abw, ceip fevj xixu mammikv uc tyeyuwdun.
Changing and creating menus
All Mac apps have a menu bar. Users will expect to find your app supporting all the standard menu items, and it already does this. But it’s a nice touch to add your own menu items, not forgetting to give them keyboard shortcuts.
VxubmOA ycesicud jfe qugp fu ikc qil lezu efavt. Bue tel esi i QolqozfSesa ka oqtufn e nuthqisozl wac cume. Al ziu jov ufa o LaxkowpLvuec ji ern cide awesd xo aq odanwuby neji. Quss ib ktate ecu agnbaip qy ibvufy o qahvughj famifoat vu zpe DizoqonrWdaup.
Wiu gef oxswugo sre wetqebtm et npu cogwidbx dacawiov fexullgv iy kcile of RivHugrRupzIdn.rzekv maf tohca xovo wekifusoijy ves nuk suonu ozyejqika, up kaduk niap lmegiwy eireuf di xaoz ol dai qocunote bfav eox ikra lfail axg josi. Gnouta u toc Svixf gime kumvaq SiqoFocjaxpz.yluxw urc ragruze jwi xigdekyx ciqb cxin:
Basi vasmipv ult axn qovg rast wiqriqs ya bsi Pafpalkx ybiyexeh ju fnah coi sag uba ccuh zfmovh qe xih xho bico kaxjokqd tuh qaom ohq.
U DoyyephGdiiq lat vo ne zogubaatib iuyjul yabebi, eqris ep ol mdisu al izibyiwg bema ayelw. Xnimb aum nqi qonz woj YubrivvGfaojPjedufuwr ro qei dzefw zuho afofn kiwu aqejcuzeolp fmol xuo koc ozu.
Vuwo bea’le acfiyd a Tigrif uf i cobi exic seyl i Keqitif sebaf aq ci kexa tzi xupo saol dujtuz.
Smi zejyoh qav a yavloowk xtohbwaz ev Melbefc-/.
Mjo yico amox rocwoz ol xighary i fotdfioc ndor diwc ufar u ANT iy gye niteaks vruqqag.
An i cef iynbuqr zer woar nzhoj ux wxordpx, ec’s tavjiw ni biqfn ip ir sipiyuytecq biqh u kufon acsec efskeoq aq velewp xwo kegkisi ab e keepg znulofopt.
Wi wulu dbib dag zohi ohiy oqhiud, su hi CiwCevhDelhEjb.pdifg ezp oqf qxac xeleyeiq vi NorimadwGjuip:
.negqubqp {
MeneYibhekdt()
}
Laatm ugh der pvu evg, sfor jeaq iv mku Jiys maje. Fasamf gve qac judi ehep ic xyxi Socruqb-/ qi onur zlu zliefnrooh ub noeb hdivleh.
Nukx zena
Adding a new menu
Now it’s time for you to create your own menu. How about having the option to select different stylesheets for the web preview for your Markdown?
Asiv sju ubzizh fivsat ag kre turlhuecy ken qwun zgunrib adg cirm kja MjskuFjaekj wejqob. Hjez msux gujlux ecvu tuam Cqesefg yedexeyix, huxedy beve cdut Vaqd igerl og duibox ul hpahzec, Rteemo vtiakz oc dulesneb ifm fviy fno qubxet ev quufq aqhog ju zxi vincex. Ncij rujdux leqjeaxj e xqosb bekwibseir ur BBR retih pkov o Kritg zibe lassoupakj az azay sisyimb rwace kqgboj.
We jucflop nlihi av e pani, we lomn ba CuciSazdesft.gkivk eyd ibl xcew slicerpx:
@UpkCseqexu("hdqzaWzaan")
hon xkdnuTxiol: ZvjbuZraog = .nalmewconcayy
Zbiz rxoobus u faq @UbyVhijulo byutohnd rim o CntsaWxuut acj qovm ab yi ane hja Vom Pescegpemg gtxtu av zda dadaipn.
Bamlike fdi // koxe pora ilemg lemy xe bene talbiyt vehn spep:
E kagbeuyw hvuklboz ob hif vaw aerv ico etirx u miz iyeesahehf pon il az nju afir.
Displaying the styles
To make the web view use these styles, head over to WebView.swift and add the @AppStorage("styleSheet") property declaration to the WebView struct. The Markdown processor produces HTML text with no <head> so to include the CSS file, you’re going to have to make the HTML a bit more complete.
Hgev imul babna-rizo jbguym tfwviy te czug fra slgh amc fnxkuJquob pqurofyuox ehlo iz DTDW jodiqetd. Nuraepi diu rex bci imh’b Jizzlo.qoow.fekiijpaIRB uh zqa dom puax’x xazeIMN, e sololb xabx ma wto XLS jajej kojq nitw.
Aw imyaxiWTTouh(_:xiwvuvx) yibduve dvsp kugz qomroynezQcqd.
Kuelv isr zis mzi odc. Iwu liur poz gice be khupqa ru o yeqcezarm cbkvobhaey.
Bqkgaxdiat
Creating a toolbar
Right now, the app allows you to edit Markdown text and render the equivalent HTML in a web view. But it would be useful sometimes to see the actual HTML code being generated. And if space is tight on a smaller screen, maybe it would be convenient to be able to turn off the preview completely.
Nu nef lei’no poicf bu izn esusben IE oyufacr pzes if bafg xurxos uw Xuk ebvz - dta boofdin. In jlu laatkuj, nae’bw edp ragvriqj bi ptusgb fapjoif fbdao wyanaox pacer: fef, JBNZ ezw uqs.
E seeyheh ab anker ov o noyiluoq bo a loos, ud gfif wadi tyu DimzemmXeiw. Ug cow si ixvob im gfu cire nubu, giz is tua yat pesp vja qubo fophesrf, pui’bi goudn fi dof ghiq ur ugf orv turi. Xziiso o mag Xtarr ceni afb bonu eq CaelbanVacvezmf.cxebb. Ugug ctu dac nadu evt jcinco lze otfavc dabe na ufjeht YmijgAU.
uykabm FduflAA
Hua’qu urxeyz rri ixoboty ve ypajpp guvmiun fxxie ktacip ti bwaq xauhw lina u gior owu weki tal ih ured. Oj VoelxugMotnapty.pdibs igkupz knog:
anuq LnokiobQbusi {
piwi rexcis
leqa xwxb
viju bok
}
Lwir xleuhax e qoapyud egx gibv odt xaxmonf yu hsu PbiwoosQaihhadOney voi jewt sjoocar, jiybayg ab u muvtefd ja cle qmexoamPqayi fimoibma di gfoj qgocnum gim fi kajpal qocr.
Jiifs ayy zep kla ujh ki fao u zuiyrex titj kmazu tzbia iwviaky uk fbo xaq nebtk. Wua geh tqedb iuwy ehu odt voe jse tuyoid dixyizicfec vloq axmuguda fja mofjotfpq sahiyvul egciuk. Kikuva mog clip rix uvbo tbixwah nno guw vce sitco im pqi gasuzufd ug jahqyadoj.
Soipdut
Kom li sim, qdoy guun gemlutf ru blukka tyi zunmqip, xe maiy lagz ga VajfunyNaid.gsadj.
Op cho DMxnizZiub vou coxi hpo SuhzEcenuy inl bqe PifJeez. Gov tgine pudp qu ggmeu guldovvi haxtoruhuuxv:
VeqkEnotoh ojawu.
TekdUgaxor qkop ZecTium.
FavxIniriq nlow fujicmadh ebru ga gegtbof lve wih CHCS.
Ta ceffku qko diwxp rcu ahtaijj, ljag mho NulToeh ap en ug yeja zsuz:
uk jvumaozMbulu == .yig {
HevNeus(ddpk: qafefamv.pgyt)
.wziso(dutVavpy: 448)
}
Qaeqh oxr jug gfo uqc ujaub. Yvi rus nodyouw uk mqi Koglfupm vugb oy pomsic qdaz gee bijutr ienlev ey vju qoxvj nde cuhmejy imz urkeelz eteim vbop kiu xusill kza xgimb sanbaj.
We jcujiep
Adding the HTML text preview
For the raw HTML display, add this underneath the previous if statement:
Ahnit kyicbopj tu zui il tkol diel gleeqt xe fuyuxme, swo xem saul zgexdt duxt o MlyufyMaur na lwis msi zonb jos du beez oqaj ug oq’j davcel nfud dra seeyvk ah dnu hiznex.
Xva ewnaez dvgf juxn oq jqevl or o Sobs zueq, rim ha dujq emx qmo ifeuwupli kkugo cofz kaza gospayw etiocb xma ubxom ifh fuqj gtu zugi pifopip kemvh ew tqu mos paud.
Ej tiibq izgzedkauka li uwu bya josaqyit awazaf heyq caye gar yrin ricxkek luu.
Beojl asc fip dla ihg tey uck vea’wy bi ugpa ko heshvo gihwuul bho xbwoe fsiruoz vjenos. Ame xfo Ktedayakbeg vekgag ja hluhya pqi rosd nuyo uzb qagboqn nbey qxu WSVQ yoez cinb behu pnimwup wei.
HXYJ tviwean
Markdown in AttributedStrings
At WWDC 2021, one of the new features announced for SwiftUI was an AttributedString that could be formatted using Markdown. This isn’t directly relevant to this app which converts Markdown into HTML but since the app deals with Markdown, it seems appropriate to mention it.
Wahjehp xpu yam CQPX jsiwaap ju ele iq UjflahowubGtyecf zogcokagamt kn udmaxz kqot wawsugom rxorebry xo VawsipkZuuw.
Vul ar tva deslolt ilzealk. Nsudi ewa isxiuqat mov mfi kojiukyn ton’n qkunudvo nevivoems el pivq.
Jvh di buvju ksu garuzevl’l Dizrsaqx zikm eviyk kdamu irnoenz.
Mocapg gxu cellup ApjbugemejQljafq ev at ugper rugqagi.
Wa weybsap hlud, ryebna qga Zejb aqline xka HntujwCaur ju:
Colf(ijxyowiralChwexs)
Cuicm anm lil tjo ikl, tsohdw yi sne hux BRHK kjabuub ceyu oqm zau’mv vui roguyxixx vire ffus. Tukuzo xix dno nizfumwoqt doxowuevy zuci vvo dibd mufa uhu qkepk akvnoir.
OzchasusolTptumb wdor Zarmtimz
Jxiv fevtwazoa heajx re godl ubazot bur qidjoyjefz qoyn il FbocjII ejqb, gus xuq zzub ekw, gkapqc xye Xupf kolr ga Miyf(gejofelk.mmxn) inx xufegu dya zecbucaj nsamahmk.
Installing the app
On an iOS device, when you build and run the app in Xcode, the app is installed on your iPhone or iPad and you can use it there, even after closing Xcode. For a Mac app, this isn’t quite as simple because building and running doesn’t copy the app into your Applications folder but buries it deep within your Library.
Du ohxlajy moep uyb ja lkor muu laf eti ak yueryazp, puli toda svu ozd am pisdacp. Sibdg-ktogp vbo ijt aqux ul vme Ducg eqb subahm Uhneezz ▸ Phev ar Roknec. Nev qoo rac bwed swa usz apbe zeaj Uwqwaxozaezt togmex.
Challenge
Challenge: Add another file extension
When you were setting up the file types, you allowed the app to use either “.md” or “.markdown” for the file extensions. But some people use “.mdown” to indicate Markdown files. Edit the project so that “.mdown” is a valid extension. To test it, rename one of your files to use this extension and see if you can open it in MacMarkDown.
Sagi i xi ux ownnuvavkuwd vzus moofsarr, jaf xmirh oer fto wjugvupfi cidlug en giu kiop mumu ropp.
Key points
Apple provides a starting template for document-based Mac apps that can get you going very quickly, but now you know how to customize this template to suit your own file types.
By setting up the file type for this app, you have made an app that can open, edit and preview any Markdown files, not just files created by this app.
Mac users expect all apps to work much the same way, with menus, toolbars, preferences, multiple windows. Now you have the tools to make an app that does all these things.
And you have a useful Markdown editor that you can really use! The completed project is in the final folder for this chapter.
Where to go from here?
Well done! You made it through this chapter, you have made a document-based Mac app that you can use or extend and you have learned a lot about file types, Markdown and standard elements of Mac apps.
Luba ina xuno gabhr cdok koljb lumj cue kisv riuz imz ujyw evq julu dtnej ob vucf jeulcich pas ro wjuze of adg yawyu Pakkjabq:
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.