{"id":175,"date":"2006-08-21T16:22:19","date_gmt":"2006-08-21T23:22:19","guid":{"rendered":"http:\/\/www.red-sweater.com\/blog\/175\/best-template-ever"},"modified":"2006-08-21T16:41:37","modified_gmt":"2006-08-21T23:41:37","slug":"best-template-ever","status":"publish","type":"post","link":"https:\/\/redsweater.com\/blog\/175\/best-template-ever","title":{"rendered":"Best. Template. Ever."},"content":{"rendered":"<p>Something I&#8217;ve been meaning to do for a long, long time, is set up some custom project templates in Xcode. The problem is, it doesn&#8217;t really take <em>that<\/em> long to tweak all the little things in a new project, so when I&#8217;m in the mood to start something new, I usually just go through all the grunt steps.<\/p>\n<p>\nToday I decided to put together a template that should cover at least 90% of the grunt work for typical applications I start work on. I started with a great example from Jon Wight of <a href=\"http:\/\/toxicsoftware.com\/blog\/\">Toxic Software<\/a>. His &#8220;CocoaApp&#8221; template did a lot of the things I wanted to do, but lacked a few whistles and bells.  I thought I&#8217;d just work from his and it would be easy.\n<\/p>\n<p>\nInstead it was amazingly, unbelievably difficult. The major complication comes from persuading Xcode&#8217;s template manager to actually do the substitutions it promises to do.  See, at the root of the template system is this behavior where Xcode will replace certain tags in your files with appropriate values for the new project. The tags are surrounded by French quotes, chevrons, whatever &#8230; you know: &laquo;these&raquo;. That&#8217;s fine, but depending on whether the file is in MacRoman, UTF-8, or UTF-16 format, the chevrons are a different value. Ugh, it&#8217;s infuriating the way they would sneak back and forth. I still don&#8217;t quite understand the logic applied by Xcode in deciding which encoding to look for, when. To make matters more complicated, I strived for (and accomplished) something truly amazing: an end to the &#8220;NewApplication&#8221; text in new project nib files. To achieve this I had to save the nib as XML format, but even then it was difficult to get the files into a suitable format that was still parseable as XML, yet would satisfy Xcode&#8217;s template system. This is so fragile that the nib files in the template are not even openable in Interface Builder &#8211; so unfortunately you won&#8217;t be able to tweak them without some serious hacking.\n<\/p>\n<p>\nBut the end result is nothing short of amazing, I&#8217;m proud to say. Download the Red Sweater <a href=\"http:\/\/www.red-sweater.com\/blog\/downloads\/RedSweaterAppTemplate.zip\">Cocoa Application<\/a> template and install it on your system. Then, when you go to create your next project, enjoy all the following frills right from the start:\n<\/p>\n<ul>\n<li>Automatically names all menu items in MainMenu.nib. No more &#8220;NewApplication&#8221;!<\/li>\n<li>Automatically instantiates a delegate class named [AppName]Delegate, connected as the delegate from NSApplication, and creates the supporting source files.<\/li>\n<li>Automatically creates an AppleScript scripting definition, pointed at by the Info.plist. The scripting definition contains a skeletal dictionary with a &#8220;[AppName] Suite&#8221;, ready for you to expose your model through.<\/li>\n<li>Automatically sets the CFBundleVersion to the <a href=\"http:\/\/www.red-sweater.com\/blog\/23\/automatic-build-sub-versioning-in-xcode\">subversion build number<\/a> through a script build phase.<\/li>\n<li>Centralizes the marketing version in one build setting called &#8220;APPLICATION_VERSION.&#8221; Just <a href=\"http:\/\/www.red-sweater.com\/blog\/32\/destroy-xcode-tedium\">change this build setting<\/a> to easily update your release version.<\/li>\n<li>Presets the application icon name to [AppName]. Just pop in a [AppName].icns file.<\/li>\n<\/ul>\n<p>\nI think that covers it. I have kindly left out the private framework references to my Red Sweater frameworks. You should be able to edit the &#8220;Cocoa Application.pbproj&#8221;  to fine-tune things to your liking, but be sure to remove the &#8220;acct.pbuser&#8221; files from within it after you do so, these have a habit of bringing some nasty values into the template which won&#8217;t get replaced by the template system.\n<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Something I&#8217;ve been meaning to do for a long, long time, is set up some custom project templates in Xcode. The problem is, it doesn&#8217;t really take that long to tweak all the little things in a new project, so when I&#8217;m in the mood to start something new, I usually just go through all [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,15,12,5],"tags":[],"class_list":["post-175","post","type-post","status-publish","format-standard","hentry","category-cocoa","category-programming","category-usability","category-xcode"],"_links":{"self":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/posts\/175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/comments?post=175"}],"version-history":[{"count":0,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/posts\/175\/revisions"}],"wp:attachment":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/media?parent=175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/categories?post=175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/tags?post=175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}