<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Extelligent Cocoa</title>
	<atom:link href="http://www.extelligentcocoa.org/feed" rel="self" type="application/rss+xml" />
	<link>http://www.extelligentcocoa.org</link>
	<description>A resource for Cocoa Programmers</description>
	<lastBuildDate>Thu, 18 Aug 2011 16:28:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Zombie File Found</title>
		<link>http://www.extelligentcocoa.org/zombie-file-found</link>
		<comments>http://www.extelligentcocoa.org/zombie-file-found#comments</comments>
		<pubDate>Thu, 18 Aug 2011 16:28:03 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Culture of Programming]]></category>
		<category><![CDATA[hidden assumptions]]></category>
		<category><![CDATA[rantage]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=301</guid>
		<description><![CDATA[In users/library there is a folder with the name of my application that contains appname.storedata I have no idea why it&#8217;s there, and why it and *only* it is there, but that was the file that created the problem. However, &#8230; <a href="http://www.extelligentcocoa.org/zombie-file-found">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In users/library there is a folder with the name of my application that contains appname.storedata</p>
<p>I have no idea why it&#8217;s there, and why it and *only* it is there, but that was the file that created the problem.</p>
<p>However, it turns out that under Snow Leopard you can no longer search for a document of type x &#8211; a search for .storedata turns up zilch. Tiger&#8217;s Spotlight app, which I liked an awful lot, has been folded into the general folder search &#8211; no more grouping of results (which was useful), no more search by predicate of &#8216;find me something of the same type as the document I&#8217;ve just dragged here&#8217; which Sherlock used to do. Dear Apple: why are we getting less functionality???</p>
<p>So I&#8217;ve found one zombie file, but have no idea whether I can find and zap all of them. </p>
<p>Onwards and upwards. And now to make a bloody tree controller work when every single tutorial I find is giving me something that throws exceptions left, right, and centre.</p>
<p>This includes Apple&#8217;s own, so I&#8217;m not singling anyone out, I am just *so tired* of not even being able to RTFM because there IS no FM that describes how to make the code work in simple steps, and Apple seems to be changing everything around and mixing it up and while I&#8217;ve specified in my app delegate that I want my app to store its data in SQLite format, I have no idea what .storedata IS. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/zombie-file-found/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to make people give up programming</title>
		<link>http://www.extelligentcocoa.org/how-to-make-people-give-up-programming</link>
		<comments>http://www.extelligentcocoa.org/how-to-make-people-give-up-programming#comments</comments>
		<pubDate>Sat, 13 Aug 2011 20:43:04 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Culture of Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[hidden assumptions]]></category>
		<category><![CDATA[rantage]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=294</guid>
		<description><![CDATA[In which Apple breaks Core Data and leaves me with an invisible, undeletable data store that is messing up development and which cost me several hours of my life. Which I want back.  <a href="http://www.extelligentcocoa.org/how-to-make-people-give-up-programming">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>- Update your Development Environment.<br />
- break 90% of your samples to that they either don&#8217;t compile because your users are using a version of the environment that is too new, or a version that is too old with a couple of things in the middle. (I&#8217;m on Snow Leopard and Xcode 4&#8230; which is a reasonable combination and I expect it to be supported).<br />
- sneak in undocumented autosave so that every mistake gets nailed down without options to undo. (I can&#8217;t be the only person ever who&#8217;ll try something, find it doesn&#8217;t work and try to revert to the previous, working, version&#8230; which no longer exists.)<br />
- break basic features in a way that is undocumented, frustrating, counterintuitive, and that takes hours to resolve.</p>
<p>What was my crime?</p>
<p><span id="more-294"></span><br />
I created an application with a Core Data model. I compiled the application, found it didn&#8217;t work, made some changes, including to the Core Data model, recompiled it, and got <em>The managed object model version used to open the persistent store is incompatible with the one that was used to create the persistent store.</em></p>
<p>I have created dozens of Core Data applications. I have changed the models in them hundreds of times&#8230; in Xcode 2.5. And every time, when I&#8217;ve used &#8216;build-and-run&#8217; I was presented with a new persistent store that WORKED.</p>
<p>This is the behaviour I expect. I&#8217;m <strong>developing</strong> an application. Once you build the finished thing, writing a permanent store and forcing developers to maintain version control and backwards compatibility is a good thing. During the build-and-run phase, it&#8217;s a <strong>very stupid</strong> behaviour. I am not creating precious, valuable data&#8230; *I am developing an application*. </p>
<p>So, I&#8217;m not the first person to run into this problem. </p>
<p><a href="http://stackoverflow.com/questions/5954541/deleting-coredata-store-on-osx"></p>
<p>The helpful answer (well, it helped the original poster), says: <em>If you use a single store for the whole application (not document based), then you should look in the code that creates the store object to find the location. The template places the creation code in the application delegate, and the default location for the store is in <code>${HOME}/Library/Application Support/${APP_NAME}/</code></em></p>
<p>So I looked there. </p>
<p>Nothing.</p>
<p>According to my app delegate, there ought to be a file named <code>Outline_Test.storedata</code>. Not on my hard drive. </p>
<p>To cut a very long story short, there isn&#8217;t a file associated with this app anywhere visibile. Even deleting the app and the project does not delete the invisible, hidden data store: creating a completely new project with the same name leads to the same compatibility error. (And gives me NO chance of restoring the old version and migrating the version: once you&#8217;ve used a name it seems as if you will never EVER be able to use it again. This is an order of bad design that makes my blood boil just thinking about it.)</p>
<p>The documentation <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdPersistentStores.html">here</a> talks about the different types of data stores and their advantages&#8230; without mentioning where you might set them. </p>
<p>You&#8217;re just automagically supposed to intuit. And yes, I *have* tried to read TFM as much as I was able to download it, and I *have* looked at each and every promising possible setting I could find, but I was not able to identify where to tell Xcode which kind of data store to use.</p>
<p>Marcus S. Zarra in his comprehensive book on Core Data&#8230;</p>
<p>&#8230; is just as silent. There&#8217;s not even an entry for sqllite in the index, and while he, too, tells you which storage formats you might choose, he omits telling you HOW TO FUCKING CHOOSE THEM. </p>
<p>I admit defeat on this one. I cannot, no matter how far I look and root around on my hard drive and search for anything associated with my damn application find the place where the data has been written. This is very very bad news, because I use Core Data a lot and I have created and run and experimented with *a lot* of Core Data apps, all of which appear to have written invisible, undeletable data SOMEWHERE on my hard drive, files which I cannot find, cannot delete, and which seems destined to hang around forever.</p>
<p>So this is a FAIL on several levels:</p>
<p>- there&#8217;s no visible or documented way of declaring the store type when you start creating your application<br />
- your application&#8217;s data is not (despite assurances to the contrary) stored in an accessible space<br />
- there is no way of clearing out that store and doing a clean rebuild during development (&#8216;This is not compatible: overwrite data store&#8217; would do just fine, thank you)<br />
- the application&#8217;s data store hangs around even when the application is deleted; it persists when you create a new project with the same name that allegedly stores its files in a different location<br />
- the documentation sucks. It completely absolutely utterly sucks.</p>
<p>I don&#8217;t know where to go from here. The sensible way forward would be to NOT run any new Core Data projects until I know where the fucking data is stored because this is creating invisible, unfindable files on my hard drive. I feel that I have gotten as far as I can &#8211; I&#8217;ve looked at the damn thing, I&#8217;ve read the documentation, I&#8217;ve searched my hard drive, I&#8217;ve rooted around in books, I&#8217;ve opened all packages (which doesn&#8217;t explain why creating a NEW project with the same name leads to the same error as before) &#8211; the long and short is that I CANNOT find the data, I CANNOT work this out, and I am completely baffled where to go for help since the hivemind of the Internet hasn&#8217;t given me any workable solution, either. </p>
<p>I expected to encounter this type of problem sooner or later, but if the app I&#8217;m trying to program is the equivalent of a novel, I didn&#8217;t expect to stumble over &#8216;It was&#8217;. </p>
<p>This is supposed to be a hobby. It&#8217;s supposed to be fun. And those people for whom programming form part of their livelyhood don&#8217;t deserve having to spend hours batting their heads against walls over very simple things, either.</p>
<p>I am deeply disappointed at Apple and am rapidly losing trust in their Cocoa development team, because this is a failure on several levels &#8211; design, preferences, documentation.</p>
<p>And I&#8217;m not imagining things. <a href="http://cocoadevcentral.com/articles/000085.php#22">CocoaDevCentral</a> says quite clearly <em>The data store is defined in the -managedObjectContext method, which is generated automatically when you create the project.</em> My <code>managedObjectContext</code> method contains no such line as<br />
<code>url = [NSURL fileURLWithPath: [applicationSupportFolder stringByAppendingPathComponent: @"BlogDemo.xml"]]; ... if ([coordinator addPersistentStoreWithType: NSXMLStoreType configuration: nil URL: url options: nil error: &#038;error]) ...</code></p>
<p>Part of that code is spread around other functions, but this means that the help I can get is not valid for the auto-generated code I am working with &#8211; as far as I can read my code it a) ought to create an XML store (<code>addPersistentStoreWithType:NSXMLStoreType</code>) in a &#8216;Outline_Test&#8217; directory (<code>[libraryURL URLByAppendingPathComponent:@"Outline_Test"]</code>).  </p>
<p>There is no such folder. There&#8217;s a <em>Outline_Test-aebwvrtqgkvjspduholxgeckmgki </em>folder &#8211; I am *so* impressed that Xcode4 is creating monster folders like this for every project I run &#8211; and that there&#8217;s nothing in the code that would indicate to me that this is going to be created. There&#8217;s also no .xml file that I can find anywhere. </p>
<p>I really truly *do* give up. And hope that someone, somewhere on this planet with more patience and more magical ability will work this out and put the solution somewhere I can find it. In the meantime, unless I want to give up programming for good, I have to resign myself to creating zombie files on my hard drive, and that makes me absolutely utterly FURIOUS. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/how-to-make-people-give-up-programming/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xcode 4 samples</title>
		<link>http://www.extelligentcocoa.org/xcode-4-samples</link>
		<comments>http://www.extelligentcocoa.org/xcode-4-samples#comments</comments>
		<pubDate>Tue, 09 Aug 2011 17:38:54 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Culture of Programming]]></category>
		<category><![CDATA[hidden assumptions]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=292</guid>
		<description><![CDATA[I found Apple's samples, but not in a place I would have looked for them.  <a href="http://www.extelligentcocoa.org/xcode-4-samples">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It appears that Apple is proving a good many samples for Xcode 4 users. </p>
<p>I needed Richard Wentk&#8217;s excellent book (entitled simply Cocoa) to find them. </p>
<p>They are interwoven with the Developer documentation. That&#8217;s the documentation you can only access when you&#8217;re online, remember?</p>
<p>If you&#8217;re not accessing it from a browser but from inside Xcode, and browse the Mac OS X Core Library, you find that it contains a lot of examples, which can be downloaded and opened. </p>
<p>(And I am *so not impressed* that half the links have been updated and are getting redirected to the main page so that the samples aren&#8217;t easily accessible after all.)</p>
<p>I liked the old way &#8211; where you could download documentation and samples in a version that would be guaranteed to run on your computer/version of Xcode &#8211; much better. If I hadn&#8217;t happened to glance at the right page in the book &#8211; and who in their right mind reads up on how to use documentation &#8211; I would have missed this feature for some time yet.</p>
<p>So now I&#8217;ve downloaded sample code for the things that interest me most &#8211; including NSCollectionView &#8211; and can start, dodgy internet connection or not, but argh. Life shouldn&#8217;t be so difficult!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/xcode-4-samples/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C Structures and Enum</title>
		<link>http://www.extelligentcocoa.org/c-structures-and-enum</link>
		<comments>http://www.extelligentcocoa.org/c-structures-and-enum#comments</comments>
		<pubDate>Wed, 03 Aug 2011 14:41:14 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Virtual Zoo]]></category>
		<category><![CDATA[Wiki]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=289</guid>
		<description><![CDATA[C code for enum and struct - I have no idea under which conditions one would use them.  <a href="http://www.extelligentcocoa.org/c-structures-and-enum">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>(This is another poin where I&#8217;m trying to work through a coding issue. I understand how structures work, I&#8217;m shaky on when and why you would declare them, what exactly you would do with them, how this fits into the greater landscape of creating objects and how the hell this plays with Core Data. </p>
<p><code>typedef enum { Domestic, Water, Land, Display } EnclosureType;</code><br />
<span id="more-289"></span><br />
If you&#8217;re using something like this purely in one small area of your application, that&#8217;s fine, but the main problem I see is that you&#8217;re hardcoding values &#8211; which sounds like a bad idea, even if you have a file where you declare all of these things globally.</p>
<p>Err, that&#8217;s the voice of experience. There&#8217;s nothing worse than wading through hundreds of possible location &#8211; even with good search capabilities &#8211; to find that you&#8217;ve originally used a different collective term for aquariums, terrariums and bird cages. And when your Zoo expands and you&#8217;re having walk-in enclosures housing birds and monkeys, good luck finding this typedef and all the places where you were counting on having only four types. </p>
<p>My understanding &#8211; and I&#8217;m happy to be corrected &#8211; is that it&#8217;s better to either create an object/CoreData entity, or to make encode such lists through the preference files (and I&#8217;m rather shaky on that part.)</p>
<p>Which brings me to the second typedef: struct.<br />
<code><br />
typedef enum { Domestic, Water, Land, Display } EnclosureType;</p>
<p>struct Enclosure_ {<br />
int enclosureID;<br />
char *enclosureLabel;<br />
float xLength, yLength, depth, height;<br />
EnclosureType enclosureType;<br />
} Enclosure;<br />
</code></p>
<p>There are two things going on here &#8211; one is definiting the structure as containing all the variables listed, the other is the naming conventions. Enclosure is a type, which is defined as a struct [which happens to be called Enclosure_]. This &#8211; according to to Trent/McCormac p. 195 &#8211; allows referring to the struct inside itself, but don&#8217;t ask me how it works or why anyone would want to. </p>
<p>You can set values in a manner similar as you would for an object:<br />
<code><br />
Enclosure elephantEnclosure;<br />
elephantEnclosure.enclosureLabel = "African Elephants";<br />
</code></p>
<p>This still looks _exactly_ like an object to me, and I have absolutely utterly NO idea why and when, in OOP, one would define a struct like this and when one would create an object. I would guess that structs have smaller footprints than objects&#8230; but when are they appropriate? </p>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/c-structures-and-enum/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sticky landing</title>
		<link>http://www.extelligentcocoa.org/sticky-landing</link>
		<comments>http://www.extelligentcocoa.org/sticky-landing#comments</comments>
		<pubDate>Wed, 03 Aug 2011 12:32:24 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Culture of Programming]]></category>
		<category><![CDATA[accessibility]]></category>
		<category><![CDATA[hidden assumptions]]></category>
		<category><![CDATA[rantage]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=287</guid>
		<description><![CDATA[Moving to Xcode 4 <a href="http://www.extelligentcocoa.org/sticky-landing">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After a lot of hard drive reorganisation, I have now upgraded to XCode 4. Since the installer is 4.5 GB and it demands 10GB free hard drive space, this was not a trivial undertaking. </p>
<p>I then went and deleted most of the iPhone stuff, leaving the system version that I&#8217;m running and the latest; which saved me about 4GB back.</p>
<p>(As usual, things are complicated. I&#8217;m not working on the latest system version; or the latest version of Xcode. And right now most of the materials I have refer to Tiger/Xcode 2.5; with the later ones optimised for Xcode 3.2&#8230; Xcode 4 is a different beast, and I&#8217;m havinng to learn it all over again.)</p>
<p>Xcode 4 does not come with documentation. None, zero, zilch, nothing. It also doesn&#8217;t come with more than three examples.</p>
<p>This is so lousy that I don&#8217;t have words for the lousyness of this arrangement.</p>
<p><span id="more-287"></span>I don&#8217;t have a permanent fast unmetered internet connection. I can read e-mails and open most webpages most of the time, but if I want broadband access I need to leave the house. Comes of living in the middle of nowhere where companies look your location up on their computer systems and go &#8216;well, ahem, that super-duper-broadband offer? Not something we can put into your house. Sorry.&#8217;</p>
<p>I don&#8217;t mind, most of the time &#8211; I have mobile broadband and an iPhone that serve my needs, and access to more internet if I need it, but an application of this complexity that comes without any documentation whatsoever is LOUSY. And with Tiger I had the difficulty that online examples were updated _to exclude running on my computer_.</p>
<p>This isn&#8217;t just a problem because I&#8217;m inconvenienced. It&#8217;s an accessibility problem &#8211; people who cannot afford to buy new computers, people who cannot afford broadband (and everybody who lives in an area where paying for fast broadband *is not an option*) are excluded. Yes, most developers probably will have the latest, fastest gear &#8211; if you&#8217;re a commercial developer that&#8217;s a must &#8211; but by setting the hurdle at a computer with the latest or almost-latest OS and unlimited broadband access, development is artificially limited to wealthy people.</p>
<p>And that&#8217;s not cool, and deserves to be pointed out.<br />
A optional download of documentation and examples would go a very long way. <!--more--></p>
<p>Xcode 4 is definitely the future. The thing I hate most is that everything is happening in one window &#8211; I want my floating palettes in Interface Builder back; I *hate* the all-in-one arrangement. I don&#8217;t like working full-screen at the best of times, and I want to be able to move palettes and inspectors out of the way. I like the new Core Data editor a lot; I like &#8211; from the little I&#8217;ve seen &#8211; the quick help and other editor features. </p>
<p>Code Snippets are made of win. (Even more win would be the ability to organise that library other than by name, but for someone like me who makes typos and forgets syntax, the ability to just drag my for and while and switch statements is wonderful.)</p>
<p>I&#8217;m not looking forward to this. I have to relearn so many things &#8211; how to create interfaces, and while I might not have been a very successful programmer, many of the things that *did* learn now have to be unlearnt and reaquired&#8230; without the body of books and tutorials to look things up if I can&#8217;t work it out on my own.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/sticky-landing/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Snow Leopard Has Landed</title>
		<link>http://www.extelligentcocoa.org/the-snow-leopard-has-landed</link>
		<comments>http://www.extelligentcocoa.org/the-snow-leopard-has-landed#comments</comments>
		<pubDate>Sat, 30 Jul 2011 14:36:02 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=280</guid>
		<description><![CDATA[I&#8217;ve upgraded my main OS from Tiger to Snow Leopard &#8211; I will continue to dual boot, but this means that I&#8217;ll have more opportunities to dabble in Xcode, and it also means that I&#8217;m moving wholly to garbage-collected code. &#8230; <a href="http://www.extelligentcocoa.org/the-snow-leopard-has-landed">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve upgraded my main OS from Tiger to Snow Leopard &#8211; I will continue to dual boot, but this means that I&#8217;ll have more opportunities to dabble in Xcode, and it also means that I&#8217;m moving wholly to garbage-collected code. It is the future after all. </p>
<p>This means I need to relearn some things, I need to tackle the basics again, and I am refamiliarising myself with the examples.</p>
<p>So imagine the wonderful surprise I got when I realised that most of Apple&#8217;s examples&#8230; *need the OS 10.4 SDK kit installed to run*. </p>
<p>Yep, you read that right. Snow Leopard&#8217;s Development tools don&#8217;t come with their own set of fully working example applications.</p>
<p>I am not impressed. </p>
<p>Am even less impressed by 2409 Errors stopping TextEdit from running.</p>
<p>No, really. I did not make up that number, 2409 fatal errors in an example that went with _Apple&#8217;s own software examples_. Really, folks. You can do better than that. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/the-snow-leopard-has-landed/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resources: Booklisting</title>
		<link>http://www.extelligentcocoa.org/resources-booklisting</link>
		<comments>http://www.extelligentcocoa.org/resources-booklisting#comments</comments>
		<pubDate>Tue, 12 Apr 2011 10:42:34 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=274</guid>
		<description><![CDATA[http://www.igor-delovski.iz.hr/forum/viewtopic.php?p=3785 has a very long list of Cocoa (OS X/iPhone) books. It&#8217;s an exceedingly comprehensive list; many of these are books I hadn&#8217;t even heard of and wouldn&#8217;t have known how to look for them. Some of them just stand &#8230; <a href="http://www.extelligentcocoa.org/resources-booklisting">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.igor-delovski.iz.hr/forum/viewtopic.php?p=3785">http://www.igor-delovski.iz.hr/forum/viewtopic.php?p=3785</a></p>
<p>has a very long list of Cocoa (OS X/iPhone) books. It&#8217;s an exceedingly comprehensive list; many of these are books I hadn&#8217;t even heard of and wouldn&#8217;t have known how to look for them. Some of them just stand on their own, some have brief reviews, but if you want a bookshelf to browse, this is hands-down the best I have seen. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/resources-booklisting/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Encapsulation: the First Principle</title>
		<link>http://www.extelligentcocoa.org/encapsulation-the-first-principle</link>
		<comments>http://www.extelligentcocoa.org/encapsulation-the-first-principle#comments</comments>
		<pubDate>Mon, 11 Apr 2011 23:57:18 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Application Development]]></category>
		<category><![CDATA[Virtual Zoo]]></category>
		<category><![CDATA[encapsulation]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=271</guid>
		<description><![CDATA[Encapsulation as the principle that underlies almost every aspect of a Cocoa application. This post contains both the concept and a practical example from the Virtual Zoo. <a href="http://www.extelligentcocoa.org/encapsulation-the-first-principle">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Encapsulation isn&#8217;t a just a feature of Cocoa, it is shared by all object-oriented programming. It is so fundamental that it&#8217;s worth dragging it into the spotlight before talking about anything else. The principle of encapsulation means that you are keeping things separate so you can make changes &#8211; sometimes substantial ones &#8211; to the individual parts without breaking the application. </p>
<p>Major areas where encapsulation plays a role:</p>
<ul>
<li>Model/View/Controller</li>
<li>Objects</li>
<li>Accessor Methods</li>
<li>Data Encapsulation</li>
</ul>
<p><span id="more-271"></span><br />
<span id="Data_Encapsulation"><H4>Data Encapsulation</h4></span>
<p>is the easiest to explain. Don&#8217;t use <code>finalPrice=basePrice + 17.5%</code> in your application. If the VAT rate changes, you&#8217;ll have to hunt down every instance, and you&#8217;ll miss them, and in five years you might no longer know where that &#8217;15%&#8217; figure came from.<br />
Define &#8211; and since VAT is something you&#8217;ll use in a number of contexts, this should be a global variable &#8211; <code>float valueAddedTax=20%</code> (float? syntax? I need to look this up) and use <code>finalPrice=basePrice + valueAddedTax</code>. This means you only need to change the value in one single place *and* your code will be more readable. Double Win.</p>
<span id="Accessor_Methods"><h4>Accessor Methods</h4></span>
<p>are reasonably straightforward: instead of reading the value of an object directly, you knock on the door and ask the object to provide its value or to set itself to an new value. Each data object (with a few exceptions, but most) has a getter and a setter method. (I&#8217;ll talk about them another time, they&#8217;re a little more complex than I&#8217;m making out here &#8211; in Objective C 2.0 they can be automatically synthesized, and using the code below can create problems). The getter returns an object of the same type as the object you queried: if you want to know the value of an ImageTitle NSString, you call its <code>- (NSString *) imageTitle;</code> method. If you want to set an object to a value, you would pass it a string and call its <code> - (void) setImageTitle: (NSString*) title;</code> method. This means that you could, for instance, restrict access: a <code>-(int) salary;</code> method might want to check whether the user is allowed to view that information (stupid example, but I&#8217;m lacking a better one right now), whereas a setter can check whether a value fulfills certain conditions  (checking whether a proposed password contains numbers) before proceeding. </p>
<span id="Objects"><h4>Objects</h4></span>
<p>Object classes have a public interface &#8211; the bit where you can see their instance variables, their outlets and action methods, and their methods. [I sincerely hope that's all]. (This is the .h file.)They also have an implementation (in the .m file): and as long as you return the expected values, it doesn&#8217;t matter by which route you arrive there. </p>
<p>The Virtual Zoo should include a &#8216;calculate my route&#8217; button, where visitors can say how they want to spend their day. The idealRoute class will contain a <code>- (void) calculateIdealRoute: (NSArray*) desiredStops;</code> method that takes an array of places a visitor wants to see and calculates a route through the zoo based on that information. There are dozens of ways that the input can be calculated &#8211; the user might just click on a map, or choose from dropdown menus, or answer a number of questions (such as how much time they have and whether they&#8217;ll want icecream or hot food at lunchtimes) &#8211; and dozens of ways of calculating a perfect path. This does not matter as long as the class takes the input &#8211; however it was derrived &#8211; and spits out a result (whatever form that result takes and however it was calculated).<br />
You can start with a simple implementation &#8211; you can start, in fact, with a manual list of input if you want to test the calculation or with an unordered list of &#8216;first go to a, then go to b&#8217; if you want to test the input mechanism. The aplication as a whole will continue to work. This means that you will be able to make _a lot_ of changes to an application before breaking it.</p>
<span id="ModelViewController"><h4>Model/View/Controller</h4></span>
<p>The MVC model is one of the central tenets of Cocoa programming, and for good reasons. A good Cocoa application separates the Model layer (data) from the View (the way it is displayed) and the Controller (the layer that handles how the two interact. This means that you can, again, separate them. Apart from the usual benefits of being able to reuse code and switch out individual bits and test them in isolation it also means that you can perform manipulations of data without displaying it. You can search for a certain string in a bunch of files and display the lines that contains the search string, and only load and display the file if the user clicks on it. Furthermore, adding different interface controls becomes a trivial matter: if you decide you don&#8217;t just want a &#8216;list animals&#8217; menu item but that you want to provide a button, too, you connect the button (&#8216;outlet&#8217;) to the controller&#8217;s &#8216;list animals&#8217; method (&#8216;action&#8217;) and bingo.  </p>
<span id="Practical_Considerations"><h3>Practical Considerations</h3></span>
<p>So how does this work in reality? One piece of functionality I want to add to the Virtual zoo is that any time I load a picture &#8211; in any location &#8211; I want to automatically add Copyright &copy; Virtual Zoo 2011. </p>
<p>And here&#8217;s the first point of encapsulation: you don&#8217;t want to add <em>Copyright &copy; Virtual Zoo 2011</em> &#8211; you want to add <code>NSString * copyrightMessage</code> which, in turn, is composed from <code>@"Copyright ©" + copyrightHolder + copyrightYear</code>. Maybe you&#8217;ll open a branch, the Virtual Deerpark, or Zoos all over the world love your application and want to buy it, so you need to give them the opportunity to read copyrightHolder from a preference file. </p>
<p>Next step.<br />
Conceptually, there are two ways of achieving this goal: one would be to _add_ the text to the image, save the new image, and use the result in the display (admit it &#8211; probably the first thing you thought of, definitely the first thing *I* thought of); while the other is to _display_ the copyright notice on top of the image in a separate view layer. The master encapsulator will choose the second version: the first one creates new data to be stored (your picture store will double, and there are *a lot* of animals in the zoo) while the second recreates a result from original objects only when needed. In general, you need very good reasons *to* store results; recalculating them according to stored rules tends &#8211; for most applications &#8211; to be not measurably slower, and saves disk space and memory. I&#8217;m taking Apple&#8217;s word for the performance aspect, but storing data several times is a bad move:</p>
<p>Adding text to an image is final, and if, next year, you decide that you don&#8217;t like the result (or if your company expands and you&#8217;re now the Virtual Zoo and Botanical Garden), the first method leaves you with the task of redoing all images again. (This, however, would be another example of encapsulating: you&#8217;d do the image manipulation without actually displaying the results, just as a background batch conversion.)</p>
<p>So when would you want to create the image-with-notice as opposed to just displaying the notice on top of the image? Any time you want to export an image out of the application. Why would you do that? Even if you have no idea, you can create an &#8216;exportableImage&#8217; class that returns the flattened image. You don&#8217;t need to know who is going to ask for that image; just that you&#8217;ll provide one. And you can start with a simple method (position copyrightMessage automatically in bright green in the bottom righthand corner). Once you&#8217;ve finished all other programming tasks, or if the appearance bothers you, you can modify it: turn copyrightMessage into an NSAttributedString that the user can change, for instance, until it&#8217;s readable. Or offer the ability to drag the message around so it can appear anywhere on the image. Or maybe you want to add a sophisticated &#8216;invisible&#8217; key signature to the image. Doesn&#8217;t matter: all you need to do is modify the exportableImage class accordingly. As long as the code itself works and <code>- (id) exportableImage;</code> returns an image, you&#8217;re golden. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/encapsulation-the-first-principle/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Procedural vs. Gestalt: A declaration of intent</title>
		<link>http://www.extelligentcocoa.org/procedural-vs-gestalt-a-declaration-of-intent</link>
		<comments>http://www.extelligentcocoa.org/procedural-vs-gestalt-a-declaration-of-intent#comments</comments>
		<pubDate>Sat, 09 Apr 2011 10:28:49 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Culture of Programming]]></category>
		<category><![CDATA[EC meta]]></category>
		<category><![CDATA[Teaching Programming]]></category>
		<category><![CDATA[accessibility]]></category>
		<category><![CDATA[Gestalt]]></category>
		<category><![CDATA[hidden assumptions]]></category>
		<category><![CDATA[learning styles]]></category>
		<category><![CDATA[teaching resources]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=258</guid>
		<description><![CDATA[A firm comittment to providing an alternative conceptual approach to programming without comitting the mistake of assuming that what's easy for me is 'easy'. <a href="http://www.extelligentcocoa.org/procedural-vs-gestalt-a-declaration-of-intent">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In the past week, I&#8217;ve come to the realisisation that I&#8217;ve banged my head against walls for a year totally sucking at programming and being made to feel stupid over and over for not understanding even &#8216;simple&#8217; things _because all the learning materials I&#8217;ve had access to were targetted at people with a different learning style_.<br />
<span id="more-258"></span><br />
In the light of how much more sense everything makes now that I&#8217;ve got the right conceptual approach &#8211; I think I need to acknowledge that maybe the conceptual approach I&#8217;ve batted my head against, that seems unlogical, and impossible for *anyone* to learn _from_ efficiently <strong>is</strong> efficient&#8230; for people who think like that. (Some things &#8211; like omitting vital information &#8211; aren&#8217;t going to be efficient for anyone.) </p>
<p>Maybe I am doing the authors of the &#8216;here are seemingly random pieces and you&#8217;ll make sense of them at the end&#8217; resources a disservice: maybe their brains *do* work like that. Maybe it *is* possible for them to learn how to do one example and then turn it into something else. Maybe they would feel the same frustration in reverse if they had to start programming my way, with high-level concepts working down to the nitty-gritty of message sending. </p>
<p>Since most of my problems seem to have stemmed from encountering materials that do not cater to my learning style, maybe the greatest danger here is to assume that everybody learns like I do; that my explanations and my journey through the programming process are _better_ than what has gone before, instead of merely radically different to most. If everybody adopted _my_ model, people who don&#8217;t learn like me will feel just the same frustration and bang their heads against their own walls.</p>
<p>I can&#8217;t promise I&#8217;ll stop ranting about the people who make programming needlessly difficult or who discourage would-be learners by telling them that this is the one and only way, that everybody learns to program like this (and if you can&#8217;t learn it this way, you&#8217;re either not working hard enough or you&#8217;ve got no talent and ought to find another hobby). That assumption &#8211; my way or the highway &#8211; is, at best, based on ignorance of learning styles and of the fact that there *is* another way to approach programming, and at worst exclusive and elitist, but I would serve the cause &#8211; making programming easier &#8211; badly if I comitted the same error in the opposite direction and made anyone else feel stupid for not learning the way *I* do.  </p>
<p>I&#8217;ve spent more than a year banging my head against various walls, being told that progamming is insanely difficult, and being made to feel stupid for not getting it. The only reasons I haven&#8217;t given up were that a) I have an application I want to realise, b) I am bloody stubborn, and c) I *know* that I&#8217;m a good application developer, just not &#8211; as yet &#8211; a good _Cocoa_ Application developer. </p>
<p>In that process of trying to learn and banging my head against walls, I&#8217;ve vented my frustrations frequently, and I am *still* frustrated at the fact that despite the maturity of Cocoa (and Nextstep before it) the only book that seems to vaguely cater to my learning style was published in 2010 and, as a beginner, all the resources I&#8217;ve encountered made learning to program &#8211; a topic that&#8217;s complex and not without pitfalls &#8211; twice as hard and far more frustrating than it needs to be. I feel I can be forgiven for venting my frustrations but &#8211; in the light of understanding the root cause of my difficulties &#8211; I need to ensure that I move forward in a positive manner. </p>
<p>Gosh, this post includes a lot of banging my head against walls, but that&#8217;s what it felt like &#8211; everywhere I turned, I encountered oblique code, bits that didn&#8217;t make sense, and a complete lack of explanations that would help me to design my own applications. I could probably find other words, but this phrase expresses my frustrations very well. I shall attempt to use it less in the future. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/procedural-vs-gestalt-a-declaration-of-intent/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Starting Programming: The Gestalt Approach</title>
		<link>http://www.extelligentcocoa.org/starting-programming-the-gestalt-approach</link>
		<comments>http://www.extelligentcocoa.org/starting-programming-the-gestalt-approach#comments</comments>
		<pubDate>Mon, 04 Apr 2011 10:25:33 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Application Design]]></category>
		<category><![CDATA[Teaching Programming]]></category>
		<category><![CDATA[Gestalt]]></category>
		<category><![CDATA[learning programming]]></category>
		<category><![CDATA[learning styles]]></category>
		<category><![CDATA[rantage]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=250</guid>
		<description><![CDATA[Using a Gestalt Approach (understanding the whole before focussing on individual aspects) as a strategy for beginner programmers. <a href="http://www.extelligentcocoa.org/starting-programming-the-gestalt-approach">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been more a year since I started seriously engaging with Cocoa programming (and no, it wasn&#8217;t a continuous process). In that time I&#8217;ve read multiple books, glanced at several others, read and followed multiple tutorials, and generally felt very frustrated with the process. </p>
<p>This morning I had another &#8216;I could have had this easier&#8217; moment that makes me want to scream with frustration: I reached &#8216;<a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaFundamentals/AddingBehaviortoaCocoaProgram/AddingBehaviorCocoa.html">Adding Behaviour to a Cocoa Program</a>&#8216; in Apple&#8217;s Cocoa Fundamentals Guide.</p>
<p>This section covers the question of what programmers are trying to do, and answers it in a conceptually different form: <em><strong>Instead of incorporating library code into your program [as you would in a procedural C application], you incorporate your program code into the framework.</strong></em></p>
<p><span id="more-250"></span><br />
Well, duh. If this had been the first thing I had encountered I could have saved myself a lot of frustration and scrambling about. It&#8217;s on page 351-of-699 in the ebook edition, and comes after the substantial &#8216;Cocoa Objects&#8217; section in that guide, and while I&#8217;ve managed to puzzle together much of what this section actually _says_, we&#8217;re back with Not RocketScience: this is the fundamental underpinning that I need in order to understand how applications work and what a programmer _does_. </p>
<p>Writing a Cocoa Application is conceptually completely different from old-school programming; it&#8217;s also a process that&#8217;s resonating a lot more with my learning style (I&#8217;m a Gestalt learner rather than procedural), and while I haven&#8217;t worked through the whole section yet, I&#8217;m already having moments of &#8216;oh, so *that&#8217;s* what&#8217;s going on&#8217;. </p>
<p>And ok, it&#8217;s hiding in plain sight &#8211; the guide IS called &#8216;Fundamentals&#8217; and if you take time to read it, you&#8217;ll reach this bit &#8211; but only after wading through a lot confusing things that will go over your head and make you reach for introductory texts. </p>
<p>I&#8217;ll go as far as to say that without understanding _ad abstractum_ how a Cocoa application works and what it does, nobody should attempt to write one. (The problem is that it&#8217;s possible to write perfectly reasonable applications without this knowledge &#8211; Cocoa makes it easy to just plug in stuff into the framework, and countless tutorials encourage the habit, but you&#8217;ll only get so far, and either screw up or put together something that&#8217;s suboptimal. My goal is to write a _good_ application, not just one that works, sort of.)</p>
<p>What I&#8217;m proposing is that would-be developers should engage with the theory first &#8211; understand what this framework is and what it does that they&#8217;re hanging functions upon &#8211; before doing the actual writing-of-functions. What have you learnt from following a &#8216;My First App&#8217; tutorial? That&#8217;s it&#8217;s very easy to write an application if you know what you&#8217;re doing and that Apple gives you a lot of features for free. That&#8217;s good and reassuring to know&#8230; but it doesn&#8217;t actually _help_ in learning how to program.   </p>
<p>Most experienced Mac users will already know most of this stuff: they know how an application works, they know how users interact with them, they know the common controls, they know &#8211; because they have seen them &#8211; many common functionalities, like the built-in text handling capabilities. </p>
<p>Using a Gestalt approach means that you take an in-depth look at what a Mac application is from the point of view of the computer, and where it has hooks you can hang your custom code and custom functionality on. </p>
<p>And THEN you delve into learning how to actually do this, but that shall be the subject of another post. </p>
<p>Having tried the procedural approach, where you learn stuff from the bottom up and put it together (I never got that far, I was missing far too many fundamental concepts) I am now attempting to try the Gestalt approach: first, get the overview and understand what I&#8217;m doing, then understand the concepts of individual aspects, then delve into the mechanics of those bits. </p>
<p>So, my first step right now is to understand how a Cocoa application works from a programming point of view. Next, I&#8217;ll work out application design &#8211; how *do* you put all those various things together? This will involve an in-depth understanding of design patterns &#8211; how objects get passed from one part of the application to another, which class is responsible for keeping track of information, how user input is processed. And last but not least, there will be function design, which involved Objective C syntax and how to deal with all potential user events and what the relevant bits of the Cocoa framework actually do and how I make use of them/override them. </p>
<p>At the end of that, I should have a working application that&#8217;s also well-designed. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/starting-programming-the-gestalt-approach/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Text Handling Overview</title>
		<link>http://www.extelligentcocoa.org/text-handling-overview</link>
		<comments>http://www.extelligentcocoa.org/text-handling-overview#comments</comments>
		<pubDate>Sat, 02 Apr 2011 13:07:01 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Wiki]]></category>
		<category><![CDATA[NSLayoutManager]]></category>
		<category><![CDATA[NSString]]></category>
		<category><![CDATA[NSTextContainer]]></category>
		<category><![CDATA[NSTextStorage]]></category>
		<category><![CDATA[NSTextView]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=239</guid>
		<description><![CDATA[I&#8217;m posting this as a mainstream post instead of merely as code snippets because I want to talk about the _conceptual_ side of text-in-Cocoa. Apple might have a long and detailed guide but, as usual, it helps me to work &#8230; <a href="http://www.extelligentcocoa.org/text-handling-overview">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<br />
<b>Warning</b>:  str_repeat() [<a href='function.str-repeat'>function.str-repeat</a>]: Second argument has to be greater than or equal to 0 in <b>/home/cpafort/extelligentcocoa.org/wp-content/plugins/wp-toc/wp-toc.php</b> on line <b>283</b><br />
<p>I&#8217;m posting this as a mainstream post instead of merely as code snippets because I want to talk about the _conceptual_ side of text-in-Cocoa. Apple might have a <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextArchitecture/Concepts/ArchitectureOverview.html#//apple_ref/doc/uid/20000839-CJBJHGAG">long and detailed guide</a> but, as usual, it helps me to work these things out myself.</p>
<p>Firstly, _storing_ text is relatively simple and has low overheads. Text files are small compared to image files, video, music, and  whatever.<br />
_Displaying_ text, on the other hand, takes up a fair amount of computing power, because in a modern OS the text is transformed into glyphs &#8211; vector files that determine the shape of each letter &#8211; and then displayed. Back in the day of bitmap display fonts, the overheads were lower (and the displays much uglier). </p>
<p>Text handling falls into three broad categories:</p>
<ul>
<li>Manipulating text strings (including storage)</li>
<li>Text Attributes</li>
<li>Displaying Text</li>
</ul>
<p><span id="more-239"></span> </p>
<span id="Anatomy_of_NSTextView"><h4>Anatomy of NSTextView</h4></span>
<p>An <code>NSTextView</code> created in Interface Builder has a <code>NSTextContainer</code> (the rectangular area text is displayed in), an <code>NSTextStorage</code> object and an <code>NSLayoutManager </code>created automatically. Understanding their basic functionality is the basis for deciding when (or whether) to subclass them (eg, when you want your text container non-rectangular.).</p>
<p>I&#8217;m mentioning this because it helped me to understand how the various things I mention below fit into the grander scheme.</p>
<div class='toc wptoc'>
<h2>Contents</h2>
<ol class='toc-odd level-1'>
		<ol class='toc-even level-2'>
<ol class='toc-odd level-3'>
			<li>
				<a href="#Anatomy_of_NSTextView">Anatomy of NSTextView</a>
			</li>
		</ol>
	<li>
		<a href="#Content">Content</a>
	</li>
	<li>
		<a href="#Attributes"> Attributes</a>
	</li>
	<li>
		<a href="#Text_Layout">Text Layout</a>
		<ol class='toc-odd level-3'>
			<li>
				<a href="#Model:">Model:</a>
			</li>
			<li>
				<a href="#View">View</a>
			</li>
			<li>
				<a href="#Controller">Controller</a>
			</li>
		</ol>
	<li>
		<a href="#Caveats">Caveats</a>
	</li>
</ol>
<li>
<a href="#Linkage">Linkage</a>
<ol class='toc-even level-2'>
<ol class='toc-odd level-3'>
	<li>
		<a href="#Antidotes">Antidotes</a>
	</li>
	<li>
		<a href="#Entanglements">Entanglements</a>
	</li>
	<li>
		<a href="#Areas">Areas</a>
	</li>
</ol>
</ol>
</ol>
</ol>
</div>
<div class='wptoc-end'>&nbsp;</div>
<span id="Content"><h3>Content</h3></span>
<p>Text is stored as a string of characters, encoded by one of several methods (UTF8 being the most common). For the most part, it will be of type <code>NSString</code> (and subtypes), and when you&#8217;re handling text in files that&#8217;s usually what you will use.<br />
<code>NSTextStorage</code> forms &#8211; as mentioned &#8211; part of an NSTextView; Apple refers to it as the <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextStorageLayer/Concepts/StorageLayer.html#//apple_ref/doc/uid/20000846-CJBJHGAG">storage layer</a>: it contains an <code>NSMutableAttributedString</code> (and is, in fact, a subclass of <code>NSString</code> and thus responds to <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html">its many methods</a> which allow the manipulation of text strings: you can find the length, break a sentence into words, insert one string into another, etc etc. </p>
<span id="Attributes"><h3> Attributes</h3></span>
<p>Attributed text has several functions. One is to aid the reader directly &#8211; they might have a preference for serif or sansserif fonts, might need a large text size or a particular colour combination to improve their reading experience. The other is to emphasize parts of a text (bolding or red for negative numbers) or otherwise structure it. (italics for thoughts, particular formatting to indicate code as opposed to explanatory text). </p>
<p>For a more detailed overview of setting font attributes, see <a href="snippets/setting-font-attributes">Setting Font Attributes</a></p>
<span id="Text_Layout"><h3>Text Layout</h3></span>
<p>I came across a chance mentioning of <code>NSLayoutManager</code>, which &#8211; until today &#8211; I had not even heard of. (The two books I have at hand right now &#8211; Trent/McCormack and Clair &#8211; don&#8217;t mention it explicitly. Fun.) <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextLayout/Concepts/LayoutManager.html">Apple&#8217;s Documentation</a> has plenty of details, and it turns out that as soon as you scratch the surface, text handling is wondrous and fascinating and far more complicated than it looks.  (This post relies heavily on Apple&#8217;s explanation.)</p>
<span id="Model:"><h4>Model:</h4></span>
<ul>
<li><code>NSTextStorage</code> (a subclass of <code>NSMutableAttributedString</code>: holds text attributes such as style etc)</li>
<li><code>NSTextContainer</code>models the geometric layout on the page</li>
</ul>
<span id="View"><h4>View</h4></span>
<p><code>NSTextView</code> (or another NSView-type object) provides the view in which the text is displayed; I am not entirely certain where <code>NSTextContainer</code> (the rectangular display area) fits into this; an <code>NSTextView</code> (see above) seems to be a cluster of things.<br />
In a scrollable view, the size of the display area can be larger than the size of the window (text view, etc).</p>
<span id="Controller"><h4>Controller</h4></span>
<p><code>NSLayoutManager</code> (according to <a href="http://www.vortimac.com/blog/?p=33">this article on subclassing it</a> is <em>the class that creates and returns the accessory view containing these common controls [eg the 'ruler' you can show in so many Mac Apps, which in turn allows for, well, layout control: justification and tabstops and styles.])</p>
<p>The <code>NSLayoutManager</code> has subsystems such as the Glyph Generator (creates glyphs from characters) and the Typesetter which places glyphs on lines according to instructions. (Aren&#8217;t you glad you don&#8217;t have to do this yourself?). (For more fun, see &#8216;<a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextArchitecture/Concepts/CommonConfigs.html#//apple_ref/doc/uid/20000840">common configurations</a>&#8216; which explains how you set up layout managers, text containers and text views depending on the kind of views you&#8217;re looking for. </p>
<p><a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextLayout/Concepts/LayoutManager.html">Apple&#8217;s Documentation &#8211; scroll down to &#8216;The Layout Process&#8217;</a> explains the process of What Happens When Something Happens (eg, a user changes text, or the application manipulates text) better than I can. </p>
<span id="Caveats"><h3>Caveats</h3></span>
<p>It&#8217;s Always More Complicated. I think this topic shows one of the main pitfalls of Cocoa programming. While you can create a text editor in 15 minutes, as per <a href="http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/TextArchitecture/Tasks/TextEditor.html#//apple_ref/doc/uid/20001798-CJBHAJJJ">Apple&#8217;s example</a>, the moment you want to delve deeper into the topic, you find a bewildering array of classes that are all somehow involved, most of which are &#8211; for reasons of complexity &#8211; not covered by the majority of entry-level texts.  </p>
<span id="Linkage"><h2>Linkage</h2></span>
<p><em>(to be implemented)</em></p>
<span id="Antidotes"><h4>Antidotes</h4></span>
<p>Graphics</p>
<span id="Entanglements"><h4>Entanglements</h4></span>
<ul>
<li>Printing Documents <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Printing/Concepts/architecture.html#//apple_ref/doc/uid/20001053-BAJCHHJG">(Apple&#8217;s Printing Guide</a></li>
<li>NSData (can also contain text)</li>
</ul>
<span id="Areas"><h4>Areas</h4></span>
<ul>
<li>Text Handling</li>
<li>Screen Display</li>
<li>Data Storage</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/text-handling-overview/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Book Not Reviewed</title>
		<link>http://www.extelligentcocoa.org/the-book-not-reviewed</link>
		<comments>http://www.extelligentcocoa.org/the-book-not-reviewed#comments</comments>
		<pubDate>Sun, 27 Mar 2011 13:46:07 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Culture of Programming]]></category>
		<category><![CDATA[Teaching Programming]]></category>
		<category><![CDATA[hidden assumptions]]></category>
		<category><![CDATA[rantage]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=235</guid>
		<description><![CDATA[Marcus S. Zarra, Core Data I&#8217;m not reviewing it for three reasons: a), right now I can&#8217;t follow the examples very far because they are OS X.5 based, b), many of the items the book talks about are beyond the &#8230; <a href="http://www.extelligentcocoa.org/the-book-not-reviewed">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Marcus S. Zarra, Core Data</p>
<p>I&#8217;m not reviewing it for three reasons: a), right now I can&#8217;t follow the examples very far because they are OS X.5 based, b), many of the items the book talks about are beyond the scope of things I&#8217;m interested in right now (though it was good to learn what&#8217;s ahead in terms of version control and data migration etc), and c) the author&#8217;s attitude on <a href="http://forums.pragprog.com/forums/90/topics/2494">this forum thread</a> annoyed me. &#8220;You need to become a better programmer&#8221; is not a sufficient answer to &#8216;your material is hard to understand and you&#8217;re leaving out explanations&#8217;. (The title of the thread will explain how I came to find it; Zarra&#8217;s use of &#8216;text area [p.20]&#8216; to refer to what looks like an NSTextView [illustration p.18] _but which is not referred to in the text otherwise_ is, to put it mildly, sloppy, and anyone who can&#8217;t follow that instruction does not need more programming experience, they need better explanations.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/the-book-not-reviewed/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NSTextView and Core Data: why do we even ask?</title>
		<link>http://www.extelligentcocoa.org/nstextview-and-core-data-why-do-we-even-ask</link>
		<comments>http://www.extelligentcocoa.org/nstextview-and-core-data-why-do-we-even-ask#comments</comments>
		<pubDate>Fri, 25 Mar 2011 13:12:46 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Culture of Programming]]></category>
		<category><![CDATA[Core Data]]></category>
		<category><![CDATA[hidden assumptions]]></category>
		<category><![CDATA[NSTextView]]></category>
		<category><![CDATA[rantage]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=232</guid>
		<description><![CDATA[Last year, when I first discovered CoreData, I experimented a little, but failed at binding an NSTextView to Core Data. Set Core Data Value[1827] *** NSRunLoop ignoring exception 'Cannot create NSData from object newTag of class NSCFString' that raised during &#8230; <a href="http://www.extelligentcocoa.org/nstextview-and-core-data-why-do-we-even-ask">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Last year, when I first discovered CoreData, I experimented a little, but failed at binding an NSTextView to Core Data.<br />
<code>Set Core Data Value[1827] *** NSRunLoop ignoring exception 'Cannot create NSData from object newTag of class NSCFString' that raised during posting of delayed perform with target 3c1890 and selector 'invokeWithTarget:'</code></p>
<p>I am not certain what exacly the hidden assumptions _are_ in this context, but there must be some, because the explanation of what is going on proved to be exceedingly simple and exceedingly difficult to find. </p>
<p><span id="more-232"></span></p>
<p>So I went and looked for an explanation. After a couple of days I gave up and wrote, rather dejectly, <em>I can display and set an attribute in a NSTextField, and I suspect this might need a value transformer, but I have no working code.</em></p>
<p>And I can see why I would have thought that, because I appeared to have passed an NSCFString to something that wants NSData, but I had no idea how to create NSData, and looking for a Value Transformer that turns my string into NSData seemed like a good idea, only such a thing was beyond me.</p>
<p>http://forums.pragprog.com/forums/90/topics/2494</p>
<p>reveals that other people are just as baffled by the problem as I was, and coming to different solutions. What I&#8217;m reading between the lines is that many programmers new to Cocoa, myself included, don&#8217;t fully understand NSTextView or how it relates to Core Data. </p>
<p>And I appear to have been right about the value transformer thing, as <a href="http://lists.apple.com/archives/cocoa-dev/2007/Jul/msg01483.html">this message to cocoa-dev</a> shows, only it now appears that the difference is between NSString and NSAttributedString, and it quickly becomes clear that <a href="http://lists.apple.com/archives/cocoa-dev/2007/Jul/msg01487.html">this wasn&#8217;t necessary at all</a>. I am including it anyway to show how other people &#8211; people successfully writing applications, so *not* complete newbies &#8211; are baffled by the same issues that baffle me. </p>
<p>Deep inside the Documentation &#8211; and I only found this because someone linked to it &#8211; in the Cocoa Bindings Reference, to be precise, lives <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/CocoaBindingsRef/BindingsText/NSTextView.html">NSTextViewBindings</a>, which under &#8216;Value Bindings&#8217; lists <em>attributedString:</p>
<p>An NSAttributedString object that contains the formatted content of the NSTextView</em> and <em>data:<br />
An NSData instance containing the formatted text of the NSTextView.<br />
The NSData contains either the RTF or RTFD representation of the NSTextView contents, depending on the configuration of the NSTextView.<br />
This binding is only available when the NSTextView is configured to allow multiple fonts.</em><br />
and<br />
<em>value</p>
<p>An NSString that contains the plain text displayed in the NSTextView.<br />
This binding is only available when the NSTextView is configured to display using a single font.</em><br />
(In other words, everybody who worked out one of those methods is right.)</p>
<p>This is completely clear and very easy to understand, but you need to know where to look for this. It would *not* have occurred to me to look in the Bindings Guide instead of the <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextView_Class/Reference/Reference.html#//apple_ref/occ/cl/NSTextView">Class Reference</a> to see what kind of data an NSTextView accepts. </p>
<p>Marcus S. Zarra&#8217;s book on Core Data, which is generally praised as being the definite book on Core Data makes no mentioning of NSTextView, so that was no help either. Googling for solutions brought &#8211; the last time I tried it &#8211; none that were helpful. </p>
<p>I&#8217;m going on about this because I feel it&#8217;s symptomatic for a lot of problems faced by Cocoa Programmers, and I&#8217;m not limiting this statement to people new to it. </p>
<p>There are two things at work here:<br />
1) People don&#8217;t understand the nature of NSTextView. By which I mean they&#8217;re not conceptualising it &#8216;as a container for NSData&#8217; which would be the easiest, or &#8216;a container for attributed/unattributed strings&#8217; (depending on your settings). I&#8217;ve yet to come across that simple explanation. I&#8217;ve seen a lot of explanation of what NSTextViews can do for you but not what they _are_, conceptually speaking.</p>
<p>2) The interface between Core Data and the rest of Cocoa is sketchy here.  Part of this might be fixed in newer versions of Xcode, but while I was able to mentally link &#8216;string&#8217; to &#8216;NSString&#8217;, I didn&#8217;t make the connection between &#8216;binary data&#8217; and the contents of an NSTextView, because &#8211; see above &#8211; I lacked a concept for it &#8211; I was too focussed on the &#8216;text&#8217; part.<br />
This is easy to fix if you want to fix it, but it exemplifies the problem. </p>
<p>As an aside, I wasn&#8217;t able to actually bind an NSTextView to a string provided by Core Data, but that&#8217;s a problem for another day. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/nstextview-and-core-data-why-do-we-even-ask/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Six meta-skills for new programmers</title>
		<link>http://www.extelligentcocoa.org/six-meta-skills-for-new-programmers</link>
		<comments>http://www.extelligentcocoa.org/six-meta-skills-for-new-programmers#comments</comments>
		<pubDate>Thu, 24 Mar 2011 23:36:10 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Teaching Programming]]></category>
		<category><![CDATA[application logic]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[function logic]]></category>
		<category><![CDATA[learning styles]]></category>
		<category><![CDATA[programming skills]]></category>
		<category><![CDATA[rantage]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=225</guid>
		<description><![CDATA[Abstract skills new Cocoa programmers need to acquire. <a href="http://www.extelligentcocoa.org/six-meta-skills-for-new-programmers">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been thinking about the intended audience of so many teaching materials, and of how this leaves out what I consider to be one of the larger groups of potential programmers &#8211; people who know Macs and how Mac applications should work, who have some experience with application development (scripting, web applications) but no actual programming background. I might or might not write that up in greater detail, but I thought I&#8217;d look at the topic from the other side. In my opinion, every new programmer should learn</p>
<p><span id="more-225"></span><br />
- how users expect to interact with applications. I&#8217;m not saying that there is no room for innovative interfaces &#8211; <a href="http://en.wikipedia.org/wiki/Kai_Krause">Kai Krause</a> comes to mind (I think Bryce is totally inspired, I wasn&#8217;t as taken with some of his other work, but I also don&#8217;t think I fully understand the _importance_ of his work) &#8211; but implementing your own interface elements is _advanced programming_ and not suitable for first projects. I feel that _especially_ people who have ben successfully creating interfaces on Windows or Linux ought to stick with the standard Mac interface and standard Mac application behaviours for a while because _this is what users expect_ and most of it exists for a reason. Knowing the rules before you break them (or before you reinvent a wheel that&#8217;s just a little bit square) is important. </p>
<p>- function logic. There is usually more than one way of writing a function, but ultimately, this is a fairly straightforward skill. Yes, it might help if you already understand a variant of C, but PHP or javascript will probably serve you just as well: you need the concepts, not the syntax. If this, then [do this], else [default]. For n repetitions, [do that]. Programming languages have operators and variables and arrays &#8211; the implementation differs, but you can look them up. I write almost everything in pseudocode first &#8211; the exact syntax is something I can look up, but the function has to make sense. For [every letter] check [whether they are vowels]. If letter = vowel, delete. That&#8217;s the same function as looping through a list of animals to check for a user-defined attribute (eg, mammal, origin: Asia, public feeding later). Function logic, for the most part, isn&#8217;t rocket science. </p>
<p>- the principles of Cocoa&#8217;s implementation of Object-Oriented Programming. I deliberately say &#8216;Cocoa&#8217; because I don&#8217;t think it is possible to separate the Cocoa framework from Objective C. (I have no idea how the other language implementations tackle the same questions &#8211; for now, I will stick with Objective C.) I struggle with this. After a year of engagement with Cocoa, I still don&#8217;t feel that I understand all of the principles well enough to explain them, which is kind of the litmus test. I cruise along, and every now and again I come across something that, on closer examination, is completely opaque to me. Mutability, for instance: because I have, with my own hands, used NSArray with a text field: how can it be an immutable object when I&#8217;ve just changed it? It took me _months_ to halfway grok what an object is and how it relates to a class; and then someone mentioned class objects that could also receive messages, and I was confused all over again. </p>
<p>- the various frameworks that make up Cocoa and what they can do for you. There&#8217;s no way you can learn all of those classes and all of their methods &#8211; but you can have an idea what functionalities you can access with a relatively small overhead. This is where a knowledge of Mac applications comes in handy: if you come across several apps _doing the same thing_ (like button toolbars or use of predicates to filter) chances are that this is a standard functionality. Apple&#8217;s documentation is pretty comprehensive, and browsing interface builder to see what&#8217;s there is a good starting point. </p>
<p>- how to put it all together. Which is the area I am weakest at, because 95% of the time when I see an example I have *no idea* by which path the programmer would have gotten there. Half the time I can, sort of, follow the code &#8211; but while it&#8217;s not an insignificant step, even very simple tutorials contain completely impenetrable use of tools. I feel that right now I have zero understanding of Cocoa _application logic_  and every time I look at someone else&#8217;s application I find something that I could not have written. Even very simple tutorials draw on a wide range of tools that I don&#8217;t understand, and I can&#8217;t work out whether this is an ideosynchratic use by a programmer who likes to do things in a particular way, best practice, the only solution (or just one of many), and, most importantly, *how the programmer knew that this tool was needed*. I mean, direct feedback is pretty straightforward: if the user clicks and object and you want x to happen, the object needs to know it&#8217;s been clicked and call an appropriate method. I get that. I don&#8217;t get why someone would use</p>
<pre class="brush: objc; title: ;">- (void)setObject:(NSArray *)aObject
{
    if (object != aObject)
	{
        object = [aObject mutableCopy];
    }
}</pre>
<p>as the setter. Why mutable-fucking-copy? Where does it come from? Why is it there? Is it necessary? Useful? Does it serve to make the code more expandable for later, will the NSMutableArray object choke on being passed aObject directly, and most importantly, *where the hell could I have learnt this*? This is a skillset that I feel is fundamental to my success &#8211; or lack of &#8211; in eventually programming my own applications, but it&#8217;s not a skill I see taught. I am particularly interested in learning about _different_ ways of implementing the same functionality. If I could see how other people think their way through a problem, which tools they reach for, and why, I would have a better chance to imitate them. And yes, I can just do the cargo cult thing and take somebody else&#8217;s solution and add my own functions, but that&#8217;s unlikely to serve me well. Doing that would mean I&#8217;d miss out on the full power of notifications and invocations and protocols and what other goodies Cocoa has to offer that *are not sufficiently explained.* I can&#8217;t reverse engineer this, and I don&#8217;t expect to be able to for several years, and in the meantime, I flail.  </p>
<p>- Cocoa Design Patterns. Thankfully, there *is* a book for that &#8211; by Buck/Yacktman &#8211; and it explains on a large scale how Cocoa applications work. I found this an exceedingly useful book. Half of it went straight over my head, but at least half of the rest made sense and allowed me to understand a little bit better what all those cryptic examples were actually doing. Or understand what they weren&#8217;t doing. In particular people who already have programming experience &#8211; in other languages, on other platforms &#8211; need to encounter this information early. The raw beginner is unlikely to get anywhere fast; the experienced programmer is much more likely to be able to cobble something together that sort-of-works &#8211; and once something sort-of-works the temptation to not pull it apart and do it again in a way that the framework was designed for, *particularly* if that way is unfamiliar and thus harder than the shortcuts you already know &#8211; can be overwhelming. Much better to learn about the tools up front. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/six-meta-skills-for-new-programmers/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resources: A Friendlier Approach</title>
		<link>http://www.extelligentcocoa.org/resources-a-friendlier-approach</link>
		<comments>http://www.extelligentcocoa.org/resources-a-friendlier-approach#comments</comments>
		<pubDate>Wed, 23 Mar 2011 14:15:10 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Culture of Programming]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[Teaching Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Bravo!]]></category>
		<category><![CDATA[Documentation]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=220</guid>
		<description><![CDATA[Very brief review of http://andymatuschak.org/articles/2007/09/09/getting-started-with-cocoa-a-friendlier-approach/ which makes tremendous sense to me. <a href="http://www.extelligentcocoa.org/resources-a-friendlier-approach">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I wish I had found this article when I first started to learn about Cocoa, I could have saved myself a lot of frustration &#8211; not because the books I&#8217;ve talked about are any less frustrating, but because someone GETS IT and gives an approach for learning Cocoa that differs from the mimetic of most books and tutorials. </p>
<p><a href="http://andymatuschak.org/articles/2007/09/09/getting-started-with-cocoa-a-friendlier-approach/">http://andymatuschak.org/articles/2007/09/09/getting-started-with-cocoa-a-friendlier-approach/</a><br />
(and read the comments as well, some of the good stuff happens in the comments.)</p>
<p>The short form of that article is &#8216;learn how Cocoa works! understand what it does! learn how to solve problems! Don&#8217;t get distracted by someone else&#8217;s shiny code!&#8217; </p>
<p>I haven&#8217;t actually worked through this yet. At some point in the not-too-far future I&#8217;ll have to jump into the deep waters of actually clawing my way through functions and classes to write some working code &#8211; I will need leisure for this, because it Will Go Wrong, but for now, I feel that I&#8217;m starting to get a feel for what I&#8217;m doing&#8230; and I am exceedingly glad that I am not alone.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/resources-a-friendlier-approach/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resource: Apple Developer Documentation</title>
		<link>http://www.extelligentcocoa.org/resource-apple-developer-documentation</link>
		<comments>http://www.extelligentcocoa.org/resource-apple-developer-documentation#comments</comments>
		<pubDate>Wed, 23 Mar 2011 13:47:22 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Resources]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Documentation]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=216</guid>
		<description><![CDATA[Parts of Apple's Developer Documentation are available free in the iBook store. <a href="http://www.extelligentcocoa.org/resource-apple-developer-documentation">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Several of of Apple&#8217;s guides are available &#8211; free &#8211; in the iBook store, so I am currently reading the Cocoa Fundamentals Guide on my iPhone. I&#8217;m on page 106 of 699, and so far, it&#8217;s been a very useful read. Yes, I *do* know some &#8211; most &#8211; of these things already, but they&#8217;re put together in a form that makes it easier to understand how they all hang together. </p>
<p>For the moment, I am going with the &#8216;read as much as I can&#8217; approach &#8211; it doesn&#8217;t help me to write code, but I feel much less overwhelmed by the code I encounter. Making sure I understand _everything_ is very timeconsuming, but it should prevent me from making fundamental mistakes later on, because copying other people&#8217;s half-digested code out of context is *not* a route to programming success.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/resource-apple-developer-documentation/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cocoa Font Attribute Handling</title>
		<link>http://www.extelligentcocoa.org/cocoa-font-attribute-handling</link>
		<comments>http://www.extelligentcocoa.org/cocoa-font-attribute-handling#comments</comments>
		<pubDate>Tue, 22 Mar 2011 14:43:24 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Culture of Programming]]></category>
		<category><![CDATA[Teaching Programming]]></category>
		<category><![CDATA[NSAttributedString]]></category>
		<category><![CDATA[NSFont]]></category>
		<category><![CDATA[NSFontManager]]></category>
		<category><![CDATA[rantage]]></category>
		<category><![CDATA[text styles]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=213</guid>
		<description><![CDATA[In which the principles of handling font attributes remain oblique. <a href="http://www.extelligentcocoa.org/cocoa-font-attribute-handling">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I am currently working through _David Chisnall: Cocoa Programming Fundamentals_ because it gives me a chance to engage with various Cocoa topics. I&#8217;ll write a detailed review once I am finished, but it&#8217;s a very frustrating resource: firstly, because the author uses a lot of shortcuts and very specific code that only serves to make it harder to understand what is going on on an abstract level, and second, because it&#8217;s full of hidden assumptions. One of them is the assumption that readers will somehow know how font styles are handled in Cocoa. </p>
<p>I&#8217;ve described the actual mechanics of setting a font attribute (font family) in <a href="snippets/setting-font-attributes">this snippet</a>, but it was, of course, too much to hope that I could actually use that example to understand font attribute handling in general&#8230;</p>
<p><span id="more-213"></span></p>
<p>I meant to include a brief rant, but due to the circumstances of this topic &#8211; <strong>there are at least two conceptionally completely different ways of styling text in Cocoa</strong> &#8211; this whole post is turning into one.<br />
(<strong>ed. to add</strong>There&#8217;s also NSAttributedString which also stores attributes, but I have no idea what it&#8217;s conceptual relation is to the other two. My suspicion would be that one method relate to the container &#8211; the text field &#8211; while NSAttributedString refers to its contents and that it makes a difference to copy-and-paste operations, but I really have no idea whether that is the case and what the hierarchy is and how you override it or&#8230;) </p>
<p>I don&#8217;t think I have seen any resource yet that explains *how* Cocoa handles font attributes. Almost every book is dealing with the mechanics &#8211; ways of setting font attributes. Cocoa gives you a lot of abilities for (near) free &#8211; integrate a font menu and you&#8217;re done &#8211; but the moment you try and go beyond the examples given into more depth, you&#8217;re pretty much on your own. </p>
<p>So what follows in this post is stuff that I&#8217;m extrapolating from the code I see, and I may or may not be talking sense.</p>
<p>Apple has, as usual an <a href="http://developer.apple.com/library/mac/#documentation/TextFonts/Conceptual/CocoaTextArchitecture/Introduction/Introduction.html">extensive guide on Font handling</a>, and as usual, the guide is so extensive that I&#8217;m finding it difficult to understand it. It&#8217;s very good information; there&#8217;s just too much of it, and not enough of an overview.<br />
Like a certain bear of little brain, Cocoa beginners need clear and obvious instructions, but most of all, what I need is an overview of the _principles_ before I can grapple with specific methods.</p>
<p>According to the above-linked documentation, <em>NSFontManager is the hub for font conversion—that is, changing the traits of a font object, such as its size or typeface. The font manager receives the messages from the Font panel and sends messages up the responder chain for action on the text objects.</em></p>
<p>Yes, I *do* want a translation for that. </p>
<p>Not in the least because <a href="snippets/setting-font-attributes">the snippet I link to above</a> is firmly in the realm of Radio Erewan: there isn&#8217;t a Font panel but other controls, and the object that is being acted on is an NSFont, not a text object. And I wonder why I&#8217;m having difficulties understanding explanations&#8230;</p>
<p>So, instead of halfway understanding how fonts are handled in Cocoa, I&#8217;m back to &#8216;I don&#8217;t understand this at all&#8217; which is *so* motivating. Not. </p>
<p>I don&#8217;t think that wanting a clear and straightforward explanation is too much to ask. This *isn&#8217;t* rocket science, but following various tutorials and half-baked examples might yield working code &#8211; yes, I *have done the simple text processor tutorials, I know that it works* &#8211; but it doesn&#8217;t give me an understanding of *how* it works or, in fact, what works. </p>
<p>The example I link to in the snippet does the following:</p>
<ol>
<li>create a font object</li>
<li>manipulate the font object</li>
<li>apply the font object to the text field</li>
</ol>
<p>And I can see that, I can also see the next step (in *any* pursuit, I will always look for abstractions and other applications; that&#8217;s how my brain works): if you create such an object <em>and save it</em>, you have your ready-made style, whether as a default style (applying it to any new text object) or as a user-defined style.</p>
<p>I can&#8217;t, right now, see how this is done, and yet I consider it to be an absolutely vital part of the progression:</p>
<p>This is how your user inputs text. This is how you manipulate styles. This is how you save styles. (How to manipulate text strings and how to load/save text would be different strands.)<br />
To tell users how to manipulate a style _and then stop there_ feels just a bit cruel.<br />
All the information *is* in TFM, but reading TFM takes a lot of time, particularly when you have to look up every second concept. </p>
<p>It&#8217;s not an efficient way to learn. It&#8217;s a damn frustrating way to learn, and since I spent four hours today dealing with the issue of *how to explain, in clear and simple words, how text styling works in Cocoa* I am throwing in the towel and breaking off this post without coming to a conclusion. </p>
<p>These are artificial barriers. Handling font styles in Cocoa isn&#8217;t rocket science, making those calls when you just want it to work and don&#8217;t care about _understanding_ how it works takes only a few minutes. The next step is huge&#8230; and it shouldn&#8217;t be. And yes, I&#8217;m still looking for a simple explanation on how to use Core Data with an NSTextField, another one of these apparently straightforward and inexplicably unexplained things&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/cocoa-font-attribute-handling/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorials: UR doing it right</title>
		<link>http://www.extelligentcocoa.org/tutorials-ur-doing-it-right</link>
		<comments>http://www.extelligentcocoa.org/tutorials-ur-doing-it-right#comments</comments>
		<pubDate>Thu, 17 Mar 2011 21:20:27 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Culture of Programming]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[Teaching Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Bravo!]]></category>
		<category><![CDATA[hidden assumptions]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=206</guid>
		<description><![CDATA[Review of an article about using multiple nibs which is extremely well thought out. <a href="http://www.extelligentcocoa.org/tutorials-ur-doing-it-right">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In looking for the solution for a particular problem &#8211; loading more than one .nib file &#8211; I came across the following article:</p>
<p><a href="http://www.gentlebytes.com/2009/09/coredata-bindings-multiple-nibs/">http://www.gentlebytes.com/2009/09/coredata-bindings-multiple-nibs/</a></p>
<p>Disclaimer: I haven&#8217;t actually _done_ this tutorial yet, so I don&#8217;t know whether it works, but I would like to point out the many ways in which it this tutorial is paying extra attention to eliminating potential sources of confusion and how it places this simple technique in a wider programming context. </p>
<p><span id="more-206"></span><br />
- It sets our very clearly what is is going to do in terms of abstract Cocoa techniques and gives a link to resources dealing with alternative approaches.<br />
- It restates the tutorial goal clearly, including a screenshot of the data model, and follows it with a screenshot of the resulting window: at this point the reader can sit down and wonder how _they_ would implement this, and it&#8217;s impossible to misunderstand the article&#8217;s goals.<br />
- it has step by step instructions that include &#8216;note that you could also do x, but I chose to do y&#8217;.<br />
- it clarifies instructions where necessary with code, and uses very clear naming practices <code>IBOutlet NSView *blogsPlaceholderView;</code> leaving you with *no* doubts what which piece of code is doing.<br />
- it states both what the writer was doing and how, exactly, this is done<br />
- it illustrates Interface Builder settings with screenshots, adds &#8216;leave everything else on default&#8217; and _really_ covers all steps, even the invisible ones. <em>(this was done for us in MainMenu.xib by the project template so it might not be totally obvious)</em><br />
- it gives, where appropriate, alternatives (this is how you&#8217;d do it in code)<br />
- it points out potential error sources<br />
- the second item is the same as before, but instead of just saying this, the author _writes out a short list of bullet points_<br />
- it ties problems together (we solve this problem by using this solution we have used above in a slightly different context)<br />
- it pays attention to potential sources of confusion <em>The model key path is not fully visible on the screenshot so here it is:</em><br />
- it points out where a shortcut has been taken for the sake of the tutorial, why it&#8217;s been done, what problems this might cause, and how you might fix it<br />
- it contains a conclusion placing the tutorial in a wider context<br />
- it has a link to a sample Xcode project </p>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/tutorials-ur-doing-it-right/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eschew Obfuscation</title>
		<link>http://www.extelligentcocoa.org/eschew-obfuscation</link>
		<comments>http://www.extelligentcocoa.org/eschew-obfuscation#comments</comments>
		<pubDate>Tue, 15 Mar 2011 16:54:06 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Culture of Programming]]></category>
		<category><![CDATA[Teaching Programming]]></category>
		<category><![CDATA[Obfuscated C]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=200</guid>
		<description><![CDATA[A brief brush with Obfuscated C <a href="http://www.extelligentcocoa.org/eschew-obfuscation">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A friend of mine commented that <code>points[pointCount++ % 4] = click</code> qualifies for &#8216;obfuscated C&#8217; (as in <a href="http://www.ioccc.org/">the obfuscated C contest</a>), and they have a good point: the code may be very clever, but it&#8217;s also rather dense; and especially in a learning resource, not appropriate. (Others may comment on how much difference it makes to actual applications and compilation times &#8211; apparently very little.)</p>
<p>The next example from the same resource &#8211; David Chisnall&#8217;s &#8220;Cocoa Programming Fundamentals&#8221; contained </p>
<pre class="brush: objc; title: ;">for (unsigned y=0 ; y&lt;2 ; y++);</pre>
<p>. This does not compile in my older XCode version, but at least I was able to unravel what he was doing and dissolved it into<br />
<code>int y;<br />
for (y=0 ; y<2 ; y++)</code><br />
which did.<br />
(I'm assuming that he's using 'unsigned' because the counter cannot be negative in this context and there's a slightly lower memory overhead?)</p>
<p>The main problem I see with this is that the code seems to be immensely optimised for _this_ application, _this_ function. This is a loop for writing data in a grid: two rows, seven columns - and was hardcoded, which for an example is acceptable, but I nonetheless want to turn it into </p>
<pre class="brush: objc; title: ;">int y;
int noOfRows = 2;
for (y=0 ; y&lt;noOfRows ; y++)</pre>
<p>because a hard-coded unexplained number somewhere in the middle of your sample code does not sound like a good idea to me. And sure, this is a *very* brief sample - but people like me are not unlikely to save it to a file somewhere with the note 'this works to do x' and then drag it out again because we know it works and contains no typos, and I can see that when you look at it in a year's time you might need to spent a little more effort to work out where that '2' came from and how you arrived at it, and of course you need to go and find every instance of the right '2' in your code to change - whereas if you'd just used a variable, you only need to change it once.  </p>
<p>This strikes me as one of the principles of good programming practice, actually: if you start with a simple function and expand it later - get it working, then tweak it, or get it working, then save it somewhere accessible and reuse it across a number of projects (because why should you work out the same thing over and over again?), keeping the code expandable, using variables with speaking names instead of hard-coded values, and commenting your code whenever you do something unusual (or just to document your logic) seem to me good habits to get into, because one day I will leave the realm of doing Very Simple Things and enter that of doing simple things that interact with each other in clever ways.  </p>
<p>I'm coming to wonder whether super-optimised code - that shaves off a fraction of a second here, a line there - doesn't turn into a disadvantage for the kind of thing I'm doing right now - because it seems less flexible, less easy to adapt. </p>
<p>I've got a good mind to go back to <code>points[pointCount++ % 4] = click</code> and pull it apart. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/eschew-obfuscation/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Explain Early, Explain Often</title>
		<link>http://www.extelligentcocoa.org/explain-early-explain-often</link>
		<comments>http://www.extelligentcocoa.org/explain-early-explain-often#comments</comments>
		<pubDate>Sun, 13 Mar 2011 00:10:14 +0000</pubDate>
		<dc:creator>Extelligent Cocoa</dc:creator>
				<category><![CDATA[Teaching Programming]]></category>
		<category><![CDATA[complexity]]></category>

		<guid isPermaLink="false">http://www.extelligentcocoa.org/?p=196</guid>
		<description><![CDATA[A thorough examination of the sophistication behind <em>points[pointCount++ % 4] = click;</em>. <a href="http://www.extelligentcocoa.org/explain-early-explain-often">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today I came across a function that I understood on a general level (more details on <a href="snippets/collecting-mouseclicks">this snippet</a>. I could see what it does: the user clicks the mouse four times, and the application uses those clicks to draw a Bezier curve: start point, first bezier handle, second bezier handle, end point. After the fourth click,
<pre class="brush: objc; title: ;">[self setNeedsDisplay: YES];</pre>
<p> is called, and the whole thing is drawn.</p>
<p>Fine, done, move on.</p>
<p>Only&#8230; I hadn&#8217;t understood how, exactly, the function worked. I hadn&#8217;t understood that you could _do_ this with Objective C. The line that got me was
<pre class="brush: objc; title: ;">points[pointCount++ % 4] = click;</pre>
<p>.<br />
<span id="more-196"></span><br />
I was a bit &#8211; more than a bit &#8211; stumped by the <em>% 4</em> syntax, and it was maybe my good fortune that I had to leave the library and go home and ponder some more and realise that I understood what it did in the second occurrence (mark the fourth iteration: now something different happens) but not the first.</p>
<p>Googling was no help at all, because try and google for &#8216;%&#8217; and you get zilch. So I asked for help on Twitter, and was provided with the answer &#8216;modulo operator&#8217;. (Thanks, guys.). That helped a little. Now I could see how the _second_ line worked, exactly, but the first was still a mystery because there&#8217;s quite a bit of complex logic in this line.</p>
<p>I&#8217;ve learnt from past failures. This time, I am leaving no holes in my understanding behind, and if that means that I stare at a single line for a couple of hours, and poke at it, and look for examples (there is no explanation), then so be it.<br />
It *did* take me an hour to work out what was going on here, and it&#8217;s not intuitive, and even though I have engaged with Objective C and ought to have remembered the modulo operator, what exactly happens here is pretty clever. </p>
<p>The results &#8211; as I could see in another function, are points[0], points[1], points[2] and points[3]. This means that the expression in square brackets &#8211; <em>pointCount++ % 4</em> &#8211; needs to resolve to that.<br />
And only thanks to the result was I able to work out what is happening here:</p>
<ul>
<li>user clicks mouse for the first time; pointCount = 0</li>
<li>0 divided by 4 has a reminder of 0</li>
<li>the coordinates are stored as points[0]</li>
<li>pointCount is increased by 1 [pointCount++]</li>
</ul>
<p>Once you get to points[3], pointCount is then increased to &#8217;4&#8242; which immediately triggers the next line &#8211; if it&#8217;s divisible by four without a reminder, the whole thing gets drawn. </p>
<p>The things that hadn&#8217;t been clear to me &#8211; that I hadn&#8217;t known you could _do_ &#8211; were as follows:</p>
<ol>
<li>complex arithmetics to determine the position in an array</li>
<li>order of events: first the point is stored in the calculated position in the array, then the counter is increased</li>
<li>observational powers: once the variable gets over a threshhold and the if statement becomes true, something happens</li>
<li>how and when the modulo operator can be used to create a de-facto loop</li>
</ol>
<p>I absolve myself of not understanding 1). None of the examples I&#8217;ve seen so far used anything remotely like this. I knew you could use points[a], but not this.<br />
2): ditto. I&#8217;m familiar with the ++/&#8211; syntax, but not as part of more complex expressions.<br />
3) I should have understood that one. It&#8217;s pretty obvious &#8211; the user clicks the mouse and the function runs and you skip or execute the statement behind the if &#8211; but the way in which this function puts it all together is not something I would have come up with<br />
4) You can do *what*? I did &#8211; because I am maybe just a tiny bit obsessive &#8211; sit down and think about how I would implement the application logic, and the best I had come up with was the vague concept of a &#8216;for i<4' construction: store click in points[0], do it again, and again, and again, and then exit the loop and call the drawing function ([self setNeedsDisplay: YES]; is more elegant than that, too.). </p>
<p>The other thing to keep in mind is that this is a function for a limited array, and a repetitive action. Rather than adding mouseclicks to points[0] through points[3] and resetting pointCounter to 0 once it reaches 3, it is self-resetting and knows _only_ those four outcomes, even on the 528th iteration. </p>
<p>The short form is that
<pre class="brush: objc; title: ;">points[pointCount++ % 4] = click;</pre>
<p> is actually part of a very sophisticated function, and one that is not immediately obvious to someone just starting out in programming; and quite possibly - judging from some of the examples I have seen - to more advanced programmers, either. I am glad that I have encountered it - I certainly have learnt from this example (not in the least how an experienced programmer can shave many lines off a piece of code without compromising performance, just by thinking differently - but even a partial explanation of what was going on would have gone a long way. </p>
<p>Designing functions is a high-level skill, and this example makes it abundantly clear just how much skill is involved in it.<br />
My solution was a function that would run, and then take clicks 1-4 and convert them to points before doing something with that information. This example is a function that is called only when the user does something relevant (clicks the mouse) and there's no loop involved whatsoever, just a straightforward iteration: convert click, add to array, do we have four yet? if no, bye, if yes, go draw yourself. In this example, the overhead for the loop would be minimal - but it's the principle that counts: instead of waiting for the user, code is only triggered when something happens. </p>
<p>Wow, do I have a lot to learn. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.extelligentcocoa.org/explain-early-explain-often/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

