<?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>meandmark.com &#187; cocoa</title>
	<atom:link href="http://meandmark.com/blog/category/cocoa/feed/" rel="self" type="application/rss+xml" />
	<link>http://meandmark.com/blog</link>
	<description></description>
	<lastBuildDate>Mon, 16 Jan 2012 19:04:01 +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>Adding Items to NSTextView&#8217;s Contextual Menu</title>
		<link>http://meandmark.com/blog/2012/01/adding-items-to-nstextviews-contextual-menu/</link>
		<comments>http://meandmark.com/blog/2012/01/adding-items-to-nstextviews-contextual-menu/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 20:36:28 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[Mac Development]]></category>

		<guid isPermaLink="false">http://meandmark.com/blog/?p=424</guid>
		<description><![CDATA[When you add a text view to your application using Interface Builder you get access to the text view&#8217;s default contextual menu. You can open the contextual menu in your application by right-clicking (or control-clicking) in the text view. This menu lets you do things like cut, copy, paste, and check the document for spelling [...]]]></description>
			<content:encoded><![CDATA[<p>When you add a text view to your application using Interface Builder you get access to the text view&#8217;s default contextual menu. You can open the contextual menu in your application by right-clicking (or control-clicking) in the text view. This menu lets you do things like cut, copy, paste, and check the document for spelling errors. If you&#8217;ve read Aaron Hillegass&#8217;s Cocoa programming book you know how to replace the default contextual menu, but you may want to use the default menu and add some menu items to it. If you&#8217;re writing an HTML editor, you may want to add a menu item to wrap HTML tags around selected text. This post shows you how to add a menu item to NSTextView&#8217;s contextual menu.</p>
<h3>Accessing the Contextual Menu</h3>
<p>The first step to adding an item to a text view&#8217;s contextual menu is to access the menu. You can access NSTextView&#8217;s default contextual menu using the menu: method.</p>
<pre>IBOutlet NSTextView* textView;</pre>
<pre>NSMenu* textViewContextualMenu = [textView menu];</pre>
<h3>Adding a Menu Item to the Contextual Menu</h3>
<p>After you get access to the contextual menu, call NSMenu&#8217;s addItemWithTitle: method to add a menu item to the contextual menu. You must supply three pieces of information: the name of the menu item, the action, and the keyboard equivalent for the menu item. The action is the method that gets called when the user chooses the menu item. The following example adds a Tags menu item to the contextual menu with no keyboard equivalent:</p>
<pre>- (IBAction)createTag:(id)sender;</pre>
<pre>NSMenuItem* tagsMenuItem = [textViewContextualMenu addItemWithTitle:@"Tags" action:@selector(createTag:) keyEquivalent:@""];</pre>
<p>If you want to place a menu item in a specific place in the contextual menu, call NSMenu&#8217;s insertItemWithTitle: method. This method works similarly to the addItemWithTitle: method, but there is an additional argument to specify: the index (location in the menu) where you want to insert the menu item.</p>
<h3>Adding a Submenu</h3>
<p>Sometimes you need to add a submenu to a menu item. In the example I&#8217;ve been using in this article, you may decide to add a menu of tags as a submenu of the Tags menu so the user can add a specific tag. Call the contextual menu&#8217;s setSubmenu: method to add a submenu. Supply the menu to add and the menu item where you&#8217;re adding the menu. The following example adds a menu of tags to the Tags menu item:</p>
<pre>IBOutlet NSMenu* tagsMenu;</pre>
<pre>[textViewContextualMenu setSubmenu:tagsMenu forItem:tagsMenuItem];</pre>
<p>The example assumes you created a menu in Interface Builder. Add a NSMenu object to the xib file, and add items to the NSMenu object. Creating a menu in Interface Builder is generally easier than creating a menu programmatically, but you can create the menu in your source code if you want. Refer to the <em>NSMenu Class Reference</em>, which is part of Apple&#8217;s documentation, to learn more about creating a menu in code. Searching for NSMenu in Xcode&#8217;s documentation window should be enough to find the class reference.</p>
]]></content:encoded>
			<wfw:commentRss>http://meandmark.com/blog/2012/01/adding-items-to-nstextviews-contextual-menu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Saving a Property List in a File Wrapper</title>
		<link>http://meandmark.com/blog/2011/04/saving-a-property-list-in-a-file-wrapper/</link>
		<comments>http://meandmark.com/blog/2011/04/saving-a-property-list-in-a-file-wrapper/#comments</comments>
		<pubDate>Thu, 14 Apr 2011 01:20:13 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[Mac Development]]></category>

		<guid isPermaLink="false">http://meandmark.com/blog/?p=316</guid>
		<description><![CDATA[Saving a property list in a file wrapper takes two steps. First, call NSPropertyListSerialization&#8217;s dataFromPropertyList: or dataWithPropertyList: methods to create a property list. The dataWithPropertyList: method was introduced in Mac OS X 10.6. Use dataFromPropertyList: if you are supporting earlier versions of Mac OS X. NSMutableDictionary* root; NSError* error; NSData* propertyList = [NSPropertyListSerialization dataWithPropertyList:root format:NSPropertyListXMLFormat_v1_0 options:0 error:&#38;error]; Second, pass [...]]]></description>
			<content:encoded><![CDATA[<p>Saving a property list in a file wrapper takes two steps. First, call NSPropertyListSerialization&#8217;s dataFromPropertyList: or dataWithPropertyList: methods to create a property list. The dataWithPropertyList: method was introduced in Mac OS X 10.6. Use dataFromPropertyList: if you are supporting earlier versions of Mac OS X.</p>
<pre>NSMutableDictionary* root;</pre>
<pre>NSError* error;</pre>
<pre>NSData* propertyList = [NSPropertyListSerialization dataWithPropertyList:root format:NSPropertyListXMLFormat_v1_0 options:0 error:&amp;error];</pre>
<pre><span style="font-family: Helvetica; white-space: normal;">Second, pass the property list you created as the first argument to NSFileWrapper's addRegularFileWithContents: method.</span></pre>
<pre>NSFileWrapper* wrapper;</pre>
<pre>[wrapper addRegularFileWithContents:propertyList preferredFilename:@"MyFile.plist"];</pre>
<pre><span style="font-family: Helvetica; white-space: normal;">My </span><span style="font-family: Helvetica; white-space: normal;"><a href="http://meandmark.com/blog/2010/10/working-with-cocoa-file-packages/">Working with Cocoa File Packages</a></span><span style="font-family: Helvetica; white-space: normal;"> post has detailed information on file packages. Read Apple's <em>Property List Programming Guide</em> for more information on property lists.</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://meandmark.com/blog/2011/04/saving-a-property-list-in-a-file-wrapper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loading Files for Unit Testing in Cocoa</title>
		<link>http://meandmark.com/blog/2010/11/loading-files-for-unit-testing-in-cocoa/</link>
		<comments>http://meandmark.com/blog/2010/11/loading-files-for-unit-testing-in-cocoa/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 00:43:00 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://meandmark.com/blog/?p=241</guid>
		<description><![CDATA[Adding files to your unit testing bundle helps when you&#8217;re unit testing file behavior or when you have a lot of test data. This post shows you how to load files from the unit testing bundle to help you unit test Cocoa applications. Before You Code The first thing you must do is get your [...]]]></description>
			<content:encoded><![CDATA[<p>Adding files to your unit testing bundle helps when you&#8217;re unit testing file behavior or when you have a lot of test data. This post shows you how to load files from the unit testing bundle to help you unit test Cocoa applications.</p>
<h2>Before You Code</h2>
<p>The first thing you must do is get your test files in the unit testing bundle. Add the test files to your project. When adding the files, add them to the unit testing target, not the application target. Make sure the test files are part of the unit testing target&#8217;s Copy Bundle Resources build phase. When you build the project, the test files will be copied to the unit testing bundle&#8217;s Resources directory.</p>
<h2>Loading a File from the Unit Testing Bundle</h2>
<p>To load an individual file call NSBundle&#8217;s pathForResource: method. The following code loads a test XML file from the unit testing bundle:</p>
<pre>NSBundle *unitTestBundle = [NSBundle bundleForClass:[self class]];</pre>
<pre>NSString* xmlFilename = [unitTestBundle pathForResource:@"XMLTestFile" ofType:nil];</pre>
<pre>NSData* xmlData = [[NSData alloc] initWithContentsOfFile:xmlFilename];</pre>
<h2>Opening a File Wrapper</h2>
<p>To open a file wrapper, call NSBundle&#8217;s URLForResource: method to find the file wrapper. Call NSFileWrapper&#8217;s initWithURL: method to open the file wrapper. The following code opens a file wrapper from the unit testing bundle:</p>
<pre>NSBundle *unitTestBundle = [NSBundle bundleForClass:[self class]];</pre>
<pre>NSURL* testFileURL = [unitTestBundle URLForResource:@"FileWrapperTest" withExtension:@"wrap"];</pre>
<pre>NSFileWrapper* testFile = [[NSFileWrapper alloc] initWithURL:testFileURL options:0 error:nil];</pre>
<p>Substitute your file wrapper&#8217;s file extension for &#8220;wrap&#8221; in the URLForResource: call. Read my <a href="http://meandmark.com/blog/2010/10/working-with-cocoa-file-packages">Working with Cocoa File Packages post</a> for more information on working with file wrappers.</p>
<p>Keep in mind that the initWithURL: method was added in Mac OS X 10.6. If you&#8217;re running an older version of Mac OS X, call NSFileWrapper&#8217;s initWithPath: method, which was deprecated in 10.6.</p>
]]></content:encoded>
			<wfw:commentRss>http://meandmark.com/blog/2010/11/loading-files-for-unit-testing-in-cocoa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with Cocoa File Packages</title>
		<link>http://meandmark.com/blog/2010/10/working-with-cocoa-file-packages/</link>
		<comments>http://meandmark.com/blog/2010/10/working-with-cocoa-file-packages/#comments</comments>
		<pubDate>Wed, 27 Oct 2010 19:09:58 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[Mac Development]]></category>

		<guid isPermaLink="false">http://meandmark.com/blog/?p=225</guid>
		<description><![CDATA[Saving a Cocoa application’s data in a file package is not much more difficult than saving the data in a single file. This post shows you how to save your document’s data in a file package and read the data from the package. Introduction to File Packages A file package is a bundle, which is [...]]]></description>
			<content:encoded><![CDATA[<p>Saving a Cocoa application’s data in a file package is not much more difficult than saving the data in a single file. This post shows you how to save your document’s data in a file package and read the data from the package.</p>
<h2>Introduction to File Packages</h2>
<p>A file package is a bundle, which is a collection of one or more directories that appears as a single file to the user. Xcode projects use file packages. Select an Xcode project in the Finder, right-click, and choose Show Package Contents to examine the file package.</p>
<p>When should you use a file package? Use a file package when you want to save your application’s document data in multiple files. A game level editor may want to save the level layout, the level’s enemy list, and the level’s treasure list in separate files. Screenwriting software may want to save each scene in its own text file.</p>
<p>The simplest file package is a single directory that contains all the files. But you can have multiple directories to group files if you’re going to store lots of files in your file package.</p>
<p>There are two tasks you must perform to add file package support to your application. First, you must add a document type for the package to your Xcode project’s target. Second, you must implement the methods fileWrapperOfType: and readFromFileWrapper: in your NSDocument subclass.</p>
<h2>Adding a Document Type to Your Project</h2>
<p>By adding a document type to your project’s target and setting the document type as a package, your document’s data will be saved as a file package. If you don’t add the document type, your data will appear as a folder in the Finder instead of as a single file, which makes it easier for someone to accidentally delete or move a file.</p>
<p>To access the inspector for your target, perform the following steps in Xcode:</p>
<ol>
<li>Select your target from the Groups and Files list.</li>
<li>Click the Info button on the project window toolbar to open the target’s inspector.</li>
<li>Click the Properties tab in the inspector.</li>
</ol>
<p>At the bottom of the target inspector is a list of document types. You should see the following columns of information:</p>
<ul>
<li>Name</li>
<li>UTI</li>
<li>Extensions</li>
<li>MIME Types</li>
<li>OS Types</li>
<li>Class</li>
<li>Icon File</li>
<li>Store Type</li>
<li>Role</li>
<li>Package</li>
</ul>
<p>If you have a document-based Cocoa application project, there should be one document type in the list. Click the + button in the lower left corner of the inspector to add a document type if you need another one.</p>
<h3>Mandatory Document Type Fields for File Packages</h3>
<p>At a minimum, you must deal with the Name, Extensions, Role, and Package fields for your file package’s document type. For the Name field, give a description for your file type. For the Extensions field, list the file extension you want for your file type, skipping the period. If you wanted your file to have the extension .xyz, you would enter the following for the Extensions field:</p>
<pre>xyz</pre>
<p>Make sure the Role is Editor. An editor can read and write files. Select the Package checkbox to make your document type a file package.</p>
<h3>The Other Document Type Fields</h3>
<p>UTI stands for uniform type identifier, which identifies an abstract type, such as a file format. A UTI takes the following form:</p>
<pre>com.CompanyName.DocumentType</pre>
<p>MIME (Multimedia Email Extensions) types are file types a web browser uses. Web browsers don’t open file packages so you shouldn’t have to worry about setting MIME types.</p>
<p>OS Types are four-character codes for the document’s file type. Before Mac OS X, Mac applications used OS Types instead of file extensions to identify themselves as the creator of a particular file. Today, you should use file extensions and UTIs to identify a document type.</p>
<p>The Class field contains the name of your NSDocument subclass. The Icon File field contains the file name for the document icon. If you use a custom icon for your file package, enter the file name in the Icon File field. You should also add the icon file to your project.</p>
<p>The Store Type field is used by Core Data applications. If you&#8217;re not using Core Data, you can ignore this field.</p>
<h2>Writing to a File Package</h2>
<p>To write your document’s data to a file package, your NSDocument subclass must implement the method fileWrapperOfType:. This method takes the following form:</p>
<pre>- (NSFileWrapper *)fileWrapperOfType:(NSString *)typeName error:(NSError **)outError</pre>
<p>The file wrapper that fileWrapperOfType: returns is the main directory for the file package. The typeName argument identifies the type of document. You shouldn’t have to worry about the typeName argument. If there is a problem during the write, the outError argument will contain the reason for the problem.</p>
<p>In your implementation of fileWrapperOfType:, you must perform the following tasks:</p>
<ul>
<li>Create a directory file wrapper.</li>
<li>Get your data into a NSData object.</li>
<li>Create a file wrapper and add the file to a directory file wrapper.</li>
</ul>
<h3>Creating a Directory File Wrapper</h3>
<p>Call NSFileWrapper’s initDirectoryWithFileWrappers: method to create a directory file wrapper. The following code creates an empty directory:</p>
<pre>NSFileWrapper* mainDirectory;</pre>
<pre>[mainDirectory initDirectoryWithFileWrappers:nil];</pre>
<p>If you’re going to store all your files in one directory, you’re done with the directory file wrapper for now. But if you’re going to store your files in folders inside the file package, you must create a directory file wrapper for each folder and give that folder a preferred filename. Call NSFileWrapper’s setPreferredFilename: method to give the folder a preferred filename. The following code creates an empty directory named HTML inside the file package:</p>
<pre>NSFileWrapper* htmlDirectory;</pre>
<pre>[htmlDirectory initDirectoryWithFileWrappers:nil];</pre>
<pre>[htmlDirectory setPreferredFilename:@"HTML"];</pre>
<h3>Getting Your Data into a NSData Object</h3>
<p>NSFileWrapper’s methods use NSData objects to write data to files and read data from files. How you get your data into a NSData object depends on your application, but the following code shows how to convert the RTF data of a text view to NSData:</p>
<pre>NSTextView* textView;</pre>
<pre>NSData* myData;</pre>
<pre>NSRange range = NSMakeRange(0, [[textView textStorage] length]);</pre>
<pre>myData = [[textView textStorage]RTFFromRange:range documentAttributes:nil];</pre>
<p>The following code demonstrates how to convert an XML document to NSData:</p>
<pre>NSXMLDocument* xmlDoc;</pre>
<pre>NSData* myData = [xmlDoc XMLData];</pre>
<h3>Creating a File Wrapper</h3>
<p>You can create a file wrapper and add it to a directory file wrapper with one method call. Call NSFileWrapper’s addRegularFileWithContents: method. This method takes two arguments. The first argument is the NSData object you created, and the second argument is the filename you want for the file. The following code adds a file named “index” to the HTML directory:</p>
<pre>NSFileWrapper* htmlDirectory;</pre>
<pre>NSData* myData;</pre>
<pre>[htmlDirectory addRegularFileWithContents:myData preferredFilename:@”index”];</pre>
<p>Call addRegularFileWithContents: for each file you’re going to save in the file package.</p>
<p>To add a subdirectory to the directory, call NSFileWrapper’s addFileWrapper: method. The following code adds the HTML directory to the main directory:</p>
<pre>NSFileWrapper* htmlDirectory;</pre>
<pre>NSFileWrapper* mainDirectory;</pre>
<pre>[mainDirectory addFileWrapper:htmlDirectory];</pre>
<p> </p>
<h2>Reading from a File Package</h2>
<p>To read from a file package, your NSDocument subclass must implement the method readFromFileWrapper:. This method takes the following form:</p>
<pre>- (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)typeName error:(NSError **)outError</pre>
<p>The fileWrapper argument is the main directory where all the files in the wrapper are stored. You can give it a more descriptive name than fileWrapper if you want. The typeName argument identifies the type of document. You shouldn’t have to worry about the typeName argument. If there is a problem during the read, the outError argument will contain the reason for the problem.</p>
<p>If you have all your files inside the main wrapper, call NSFileWrapper’s fileWrappers: method, which contains all the file wrappers inside a directory.</p>
<pre>NSFileWrapper* mainDirectory;</pre>
<pre>NSDictionary* files = [mainDirectory fileWrappers];</pre>
<p>If you need to find a particular file or directory, call NSFileWrapper’s objectForKey: method. The following code locates the HTML folder in the file wrapper:</p>
<pre>NSFileWrapper* mainDirectory;</pre>
<pre>NSFileWrapper* htmlDirectory = [[mainDirectory fileWrappers] objectForKey:@”HTML"];</pre>
<p>Once you get a directory, call fileWrappers: to get the list of files in that directory.</p>
<pre>NSFileWrapper* htmlFiles = [htmlDirectory fileWrappers];</pre>
<h3>Reading the Individual Files</h3>
<p>When you call NSFileWrapper’s fileWrappers: method, it returns a NSDictionary object containing all the files in the directory. Assuming you want to read all the files, the easiest thing to do is create an NSEnumerator object and use that object to go through the files.</p>
<p>A dictionary contains a list of key-value pairs. The enumerator for a dictionary can either be a key enumerator or an object enumerator. For a file wrapper you should use a key enumerator that contains all of the filenames in the dictionary.</p>
<pre>NSDictionary* files;</pre>
<pre>NSEnumerator* fileEnumerator = [files keyEnumerator];</pre>
<p>Use NSEnumerator’s nextObject: method to go through the files in the dictionary. Call NSEnumerator’s objectForKey: method to get the file wrapper. Call NSFileWrapper’s regularFileContents: method to get the contents of the file in a NSData object.</p>
<pre>id currentFilename;</pre>
<pre>NSFileWrapper* currentFile;</pre>
<pre>NSData* myData;</pre>
<pre>while (currentFilename = [fileEnumerator nextObject]) {</pre>
<pre><span style="white-space: pre;">	</span>currentFile = [files objectForKey:currentFilename];</pre>
<pre><span style="white-space: pre;">	</span>myData = [currentFile regularFileContents];</pre>
<pre><span style="white-space: pre;">	</span>// Load myData.</pre>
<pre>}</pre>
<h3>Loading the Data</h3>
<p>How you load the data depends on the data you’re storing. If you store RTF data, you can use NSTextStorage’s initWithRTF: method to load a text view with the contents of a text file.</p>
<pre>NSTextView* textView;</pre>
<pre>NSData* myData;</pre>
<pre>[[textView textStorage] initWithRTF:myData documentAttributes:nil];</pre>
<p>If you’re loading an XML document, call NSXMLDocument’s initWithData: method to load the document from disk to the NSXMLDocument.</p>
<pre>NSError* error;</pre>
<pre>NSXMLDocument* xmlDoc;</pre>
<pre>[xmlDoc initWithData:myData options:NSXMLDocumentValidate error:&amp;error];</pre>
<p> </p>
<h2>Additional Information</h2>
<p>Read Apple’s documentation for the NSFileWrapper, NSData, and NSDocument classes for more information on working with file packages.</p>
]]></content:encoded>
			<wfw:commentRss>http://meandmark.com/blog/2010/10/working-with-cocoa-file-packages/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Locating the Unit Testing Bundle in Cocoa</title>
		<link>http://meandmark.com/blog/2010/10/locating-the-unit-testing-bundle-in-cocoa/</link>
		<comments>http://meandmark.com/blog/2010/10/locating-the-unit-testing-bundle-in-cocoa/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 00:49:02 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[Mac Development]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://meandmark.com/blog/?p=223</guid>
		<description><![CDATA[If you load test data from a file when unit testing a Cocoa application, you&#8217;ll need to access the unit testing bundle to find the file. Your first instinct might be to call NSBundle&#8217;s mainBundle: method. For a unit testing target, the main bundle should be the unit testing bundle, right? Unfortunately, the mainBundle: method is [...]]]></description>
			<content:encoded><![CDATA[<p>If you load test data from a file when unit testing a Cocoa application, you&#8217;ll need to access the unit testing bundle to find the file. Your first instinct might be to call NSBundle&#8217;s mainBundle: method. For a unit testing target, the main bundle should be the unit testing bundle, right? Unfortunately, the mainBundle: method is for application bundles, not unit testing bundles.</p>
<p>Call NSBundle&#8217;s bundleForClass: method to load the unit testing bundle. The following code demonstrates how to locate the unit testing bundle:</p>
<pre>NSBundle *unitTestBundle = [NSBundle bundleForClass:[self class]];</pre>
]]></content:encoded>
			<wfw:commentRss>http://meandmark.com/blog/2010/10/locating-the-unit-testing-bundle-in-cocoa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using NSZombie with Instruments</title>
		<link>http://meandmark.com/blog/2010/09/using-nszombie-with-instruments/</link>
		<comments>http://meandmark.com/blog/2010/09/using-nszombie-with-instruments/#comments</comments>
		<pubDate>Wed, 22 Sep 2010 01:29:37 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[Instruments]]></category>
		<category><![CDATA[Mac Development]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://meandmark.com/blog/?p=221</guid>
		<description><![CDATA[Cocoa&#8217;s NSZombie class helps you discover where you are accessing a deallocated object in your code. For those of you running Snow Leopard, Instruments has support for NSZombie so you can use NSZombie without having to make any changes to your Xcode project. Checking for zombies is pretty simple. Open your project in Xcode. Choose [...]]]></description>
			<content:encoded><![CDATA[<p>Cocoa&#8217;s NSZombie class helps you discover where you are accessing a deallocated object in your code. For those of you running Snow Leopard, Instruments has support for NSZombie so you can use NSZombie without having to make any changes to your Xcode project.</p>
<p>Checking for zombies is pretty simple. Open your project in Xcode. Choose Run &gt; Run With Performance Tool &gt; Zombies. Your application will launch and Instruments will trace its execution. If your application accesses a deallocated object, a zombie message appears in Instruments.</p>
<p><img src="http://meandmark.com/blog/wp-content/uploads/2010/09/Instruments-Zombie-Message.png" border="0" alt="Instruments Zombie Message.png" width="290" height="141" /></p>
<p>Clicking the focus button next to the memory address shows the history of that memory address. The Responsible Caller column tells you where you&#8217;re trying to access a deallocated object.</p>
<p>If the Run With Performance Tool option is grayed out in Xcode, launch Instruments (or choose File &gt; New if Instruments is already running) and select the Zombies template. The Zombies template is available for Mac applications and iPhone applications running in the Simulator. Use the Target menu in the trace document window toolbar to choose your application. Click the Record button to start recording.</p>
]]></content:encoded>
			<wfw:commentRss>http://meandmark.com/blog/2010/09/using-nszombie-with-instruments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Value Expressions: Where to Find Documentation</title>
		<link>http://meandmark.com/blog/2010/05/value-expressions-where-to-find-documentation/</link>
		<comments>http://meandmark.com/blog/2010/05/value-expressions-where-to-find-documentation/#comments</comments>
		<pubDate>Mon, 03 May 2010 04:40:08 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[Mac Development]]></category>
		<category><![CDATA[Core Data]]></category>

		<guid isPermaLink="false">http://meandmark.com/blog/?p=200</guid>
		<description><![CDATA[When you open a mapping model in a Core Data project, you&#8217;ll see that attributes and relationships have a value expression, and you have the option to change the value expression. For attributes the value expression is usually simple. $source.AttributeName I wanted to see what kinds of values you could give a value expression. I [...]]]></description>
			<content:encoded><![CDATA[<p>When you open a mapping model in a Core Data project, you&#8217;ll see that attributes and relationships have a value expression, and you have the option to change the value expression. For attributes the value expression is usually simple.</p>
<p><code>
<pre>$source.AttributeName</pre>
<p> </code></p>
<p>I wanted to see what kinds of values you could give a value expression. I did a Google search and found some questions from people on mailing lists and message boards from people who wanted the same information as I did. But I found no answers. After doing some more searching, I learned an important piece of information.</p>
<p>A value expression is an object of the NSExpression class. With this information I could look at Apple&#8217;s documentation. The place to start is the NSExpression class reference. In the class reference is a link to Apple&#8217;s <strong>Predicate Programming Guide</strong>. After looking at both documents, I learned value expressions are a large topic with many possible values, too many for me to answer here. But I now know where to look when I need information on value expressions. Now you know where to look too.</p>
]]></content:encoded>
			<wfw:commentRss>http://meandmark.com/blog/2010/05/value-expressions-where-to-find-documentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Started with Mac Programming</title>
		<link>http://meandmark.com/blog/2010/01/getting-started-with-mac-programming/</link>
		<comments>http://meandmark.com/blog/2010/01/getting-started-with-mac-programming/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 05:07:22 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[Mac Development]]></category>

		<guid isPermaLink="false">http://meandmark.com/blog/?p=125</guid>
		<description><![CDATA[A question that comes up often in Mac programming forums is &#8220;Where do I start?&#8221; I have gathered a bunch of information and put it in this post to answer this question. Hopefully this helps people new to Mac development and reduces the frequency of &#8220;Where do I start?&#8221; questions on the forums. NOTE: The [...]]]></description>
			<content:encoded><![CDATA[<p>A question that comes up often in Mac programming forums is &#8220;Where do I start?&#8221; I have gathered a bunch of information and put it in this post to answer this question. Hopefully this helps people new to Mac development and reduces the frequency of &#8220;Where do I start?&#8221; questions on the forums.</p>
<p>NOTE: The information in this post is for people writing Mac GUI applications, not games. You could write a Mac game without having to learn Objective-C and Cocoa. Getting started in game development would be a good topic for a future post.</p>
<h3><strong>Update for Lion and Xcode 4 Users (July 2011)</strong></h3>
<p>Mac OS X 10.7 does not include Xcode. Download Xcode from the Mac App Store. The version of Xcode on the Mac App Store includes the iPhone SDK. Xcode 4 integrates Interface Builder with Xcode. There is no separate Interface Builder application.</p>
<h3>The Tools You Need</h3>
<p>If you have a copy of Mac OS X, you have the tools you need to write Mac applications. Apple includes developer tools, the Xcode Tools, with every copy of Mac OS X. Insert your Mac OS X DVD. The Xcode installer is in the Optional Installs folder.</p>
<p>Apple constantly updates their developer tools. To get the latest version of Xcode, go to <a href="http://developer.apple.com">Apple&#8217;s developer site</a>. You will have to sign up for a free ADC membership before you can download Xcode.</p>
<p>If you&#8217;re interested in iPhone development, download the iPhone SDK instead of Xcode. The iPhone SDK contains both the Xcode Tools and the iPhone SDK. If you download Xcode, then download the iPhone SDK at a later date, you&#8217;re downloading Xcode twice, and Xcode is a large download.</p>
<p>After installing Xcode you will have all the tools you need to write Mac applications. The tools you will use the most are Xcode and Interface Builder.</p>
<p>Xcode is an integrated development environment. You will use Xcode to write your source code and compile the source code into a Mac application. You will use Interface Builder to create the user interface for your applications.</p>
<h3>Learning a Programming Language</h3>
<p>Before you can write Mac applications, you must know a programming language. If you have never programmed before, you will have to learn one. What language should you learn?</p>
<p>If you&#8217;re serious about writing Mac applications, you should eventually learn Objective-C. The Cocoa framework uses Objective-C as well as the Cocoa Touch framework, which is used to write iPhone applications.</p>
<h4>Your First Language</h4>
<p>Should you learn Objective-C first? If you post this question on a Mac programming message board, you will generate a lot of heated responses. These responses generally fall into three camps.</p>
<p>Camp 1: Learn Objective-C first. You have to know Objective-C to write Cocoa applications so you should go ahead and learn Objective-C.</p>
<p>Camp 2: Learn C, then Objective-C. Objective-C is a superset of C. It takes C and adds support for object-oriented programming. By learning C, you&#8217;ll make progress towards learning Objective-C.</p>
<p>Camp 3: Learn a language like Python or Ruby first. C and Objective-C are too difficult for a beginner. Python and Ruby are easier to learn. Start with one of them. After you learn Python or Ruby, you can move on to Objective-C.</p>
<p>Which camp is right? It depends on you and how you plan on learning Objective-C. If you plan on learning Objective-C through online tutorials, Camp 2 is right. Most Objective-C tutorials assume you know C so you would have to learn C first to understand the tutorials.</p>
<p>If you plan on learning Objective-C through Stephen Kochan&#8217;s Objective-C book (<a href="http://www.amazon.com/Programming-Objective-C-2-0-Stephen-Kochan/dp/0321566157">Amazon link</a>), Camp 1 is right. The book doesn&#8217;t assume you know C so you can use the book to learn Objective-C without learning C first.</p>
<p>If you start learning C or Objective-C and have a hard time understanding the material, Camp 3 is right. Start with another language and learn Objective-C later.</p>
<h4>Resources for Learning Programming</h4>
<p>The World Wide Web is full of programming tutorials. The following sites will give you a large collection of programming language tutorials:</p>
<ul>
<li><a href="http://www.cocoadevcentral.com">CocoaDevCentral</a> has tutorials on C and Objective-C.</li>
<li><a href="http://www.cprogramming.com">CProgramming.com</a> has C tutorials.</li>
<li>The <a href="http://www.python.org">Python website</a> has tutorials for learning Python in the Documentation section.</li>
<li>The <a href="http://www.ruby-lang.org">Ruby website</a> has Ruby tutorials in the Documentation section.</li>
</ul>
<p>Some of you will prefer learning programming from a book. You can find books on Mac programming, Python, and Ruby from the following publishers:</p>
<ul>
<li><a href="http://www.apress.com">Apress</a></li>
<li><a href="http://www.informit.com">InformIT</a></li>
<li><a href="http://oreilly.com">O&#8217;Reilly</a></li>
<li><a href="http://pragprog.com">Pragmatic Programmers</a></li>
</ul>
<p>Three programming language books that would help someone interested in Mac programming are the following:</p>
<ul>
<li><strong>Learn C on the Mac</strong> by Dave Mark.</li>
<li><strong>Learn Objective-C on the Mac</strong> by Mark Dalrymple and Scott Knaster. This book is a sequel of sorts to<strong> Learn C on the Mac</strong> and assumes you&#8217;ve read <strong>Learn C on the Mac</strong>.</li>
<li><strong>Programming in Objective-C 2.0</strong> by Stephen Kochan.</li>
</ul>
<h4>Learning Programming on a Mac</h4>
<p>If you&#8217;re learning C or Objective-C, you can use Xcode to learn the language. Create a command-line tool project for each program you write. In Xcode 3.2 take the following steps to create a command-line tool project:</p>
<ol>
<li>Choose File &gt; New Project in Xcode.</li>
<li>Select Application under Mac OS X on the left side of the New Project Assistant.</li>
<li>Select Command Line Tool at the top of the New Project Assistant.</li>
<li>Pick your language from the Type pop-up menu. Choose Foundation for Objective-C.</li>
<li>Click the Choose button.</li>
<li>Name your project and pick a location to save it.</li>
<li>Click the Save button.</li>
</ol>
<p>Those of you running Xcode 4 should click the Next button after Step 3. The Choose button in Step 5 is named Next in Xcode 4. Step 6 is split in Xcode 4. You name the project when you pick a language.</p>
<p>For those of you running older versions of Xcode, create a Standard Tool project to learn C or a Foundation Tool project to learn Objective-C.</p>
<p>Some people think integrated development environments like Xcode hide too many details from beginning programmers, which hinders learning. They suggest beginners write their source code in a text editor and compile it from the Terminal application. For more information on compiling from the Terminal, read my <a href="http://meandmark.com/blog/2008/09/avoiding-xcode">Avoiding Xcode</a> post.</p>
<p>If you&#8217;re learning Python or Ruby, I have good news. Mac OS X comes with Python and Ruby interpreters so you can start writing Python and Ruby programs right now. For Python and Ruby programming, I recommend using TextWrangler, which is a free text editor. You can write, run, and debug Python and Ruby programs inside TextWrangler. My <a href="http://meandmark.com/blog/2007/01/textwrangler-and-interpreted-languages">TextWrangler and Interpreted Languages</a> post has more information on using TextWrangler.</p>
<h3>Learning Cocoa</h3>
<p>After learning Objective-C, you can move on to learning Cocoa. Cocoa is Apple&#8217;s framework for writing GUI applications on Mac OS X. Cocoa is a large framework so prepare to spend a lot of time learning it.</p>
<h4>Cocoa Books</h4>
<p>When people ask for book recommendations on Mac programming message boards, the usual recommendation is Aaron Hillegass&#8217; <strong>Cocoa Programming for Mac OS X</strong> (<a href="http://www.amazon.com/Cocoa-Programming-Mac-OS-3rd/dp/0321503619">Amazon link</a>). This book does a good job of teaching the fundamentals of Cocoa programming. Hillegass assumes the reader knows C so his book is not right for people completely new to programming.</p>
<p>Cocoa is becoming a hot topic for computer book publishers. You can find a lot of new and upcoming Cocoa books from the following publishers:</p>
<ul>
<li><a href="http://www.apress.com">Apress</a></li>
<li><a href="http://www.informit.com">InformIT</a></li>
<li><a href="http://oreilly.com">O&#8217;Reilly</a></li>
<li><a href="http://pragprog.com">Pragmatic Programmers</a></li>
</ul>
<h4>Cocoa Learning Resources</h4>
<p>The biggest source for Cocoa documentation is Apple. You can read Apple&#8217;s documentation in Xcode by choosing Help &gt; Developer Documentation. You can also read it online at <a href="http://developer.apple.com">Apple&#8217;s developer site</a>.</p>
<p>Some other sites that will help you learn Cocoa are:</p>
<ul>
<li><a href="http://www.cocoadevcentral.com">CocoaDevCentral</a>, which has a lot of Cocoa tutorials.</li>
<li><a href="http://www.cocoadev.com">CocoaDev</a>, which has lots of Cocoa information and a forum to ask questions.</li>
<li><a href="http://www.planetcocoa.org">PlanetCocoa</a>, which is a large collection of Cocoa programming blogs.</li>
<li><a href="http://www.cocoabuilder.com">Cocoabuilder</a>, which contains an archive of Apple&#8217;s Cocoa mailing list.</li>
<li>Andy Matuschak has a <a href="http://andymatuschak.org/articles/2007/09/09/getting-started-with-cocoa-a-friendlier-approach">learning path for Cocoa</a> on his blog.</li>
</ul>
<p>This list is obviously not exhaustive. Use your favorite search engine to find more resources for learning Cocoa development and learning programming in general.</p>
]]></content:encoded>
			<wfw:commentRss>http://meandmark.com/blog/2010/01/getting-started-with-mac-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xcode 3 Addition: Python and Ruby Cocoa Project Templates</title>
		<link>http://meandmark.com/blog/2008/01/xcode-3-addition-python-and-ruby-cocoa-project-templates/</link>
		<comments>http://meandmark.com/blog/2008/01/xcode-3-addition-python-and-ruby-cocoa-project-templates/#comments</comments>
		<pubDate>Fri, 18 Jan 2008 05:45:00 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://meandmark.com/blog/?p=66</guid>
		<description><![CDATA[Xcode 3 includes project templates for writing Cocoa applications in Python and Ruby. Those of you who were turned off of Cocoa by Objective C&#8217;s syntax can now give Cocoa development a try. If you installed the developer examples when you installed Xcode 3, you will find on your hard drive many examples of Cocoa [...]]]></description>
			<content:encoded><![CDATA[<p>Xcode 3 includes project templates for writing Cocoa applications in Python and Ruby. Those of you who were turned off of Cocoa by Objective C&#8217;s syntax can now give Cocoa development a try.</p>
<p>If you installed the developer examples when you installed Xcode 3, you will find on your hard drive many examples of Cocoa programs written in Python and Ruby. You can find the Python examples at the following location:</p>
<div><span style="font-family:'courier new';">Developer/Examples/Python/PyObjC</span></div>
<p>You can find the Ruby examples at the following location:</p>
<div><span style="font-family:'courier new';">Developer/Examples/Ruby/RubyCocoa</span></div>
]]></content:encoded>
			<wfw:commentRss>http://meandmark.com/blog/2008/01/xcode-3-addition-python-and-ruby-cocoa-project-templates/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Interface Builder 3 Change: No Subclass Creation</title>
		<link>http://meandmark.com/blog/2008/01/interface-builder-3-change-no-subclass-creation/</link>
		<comments>http://meandmark.com/blog/2008/01/interface-builder-3-change-no-subclass-creation/#comments</comments>
		<pubDate>Wed, 16 Jan 2008 20:25:00 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[Interface Builder]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://meandmark.com/blog/?p=65</guid>
		<description><![CDATA[Older versions of Interface Builder let you create subclasses for Cocoa applications and generate source code files for the subclasses you created. As an example, you could drag an OpenGL view to a window, subclass the OpenGL view, and have Interface Builder create .h and .m files for the subclass. But Interface Builder 3 no [...]]]></description>
			<content:encoded><![CDATA[<p>Older versions of Interface Builder let you create subclasses for Cocoa applications and generate source code files for the subclasses you created. As an example, you could drag an OpenGL view to a window, subclass the OpenGL view, and have Interface Builder create .h and .m files for the subclass. But Interface Builder 3 no longer lets you create subclasses. How do you create the subclasses?
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div></div>
<div>You create the subclasses the old-fashioned way: with source code. Create your subclasses in Xcode. Interface Builder and Xcode are synchronized so the subclasses you create in Xcode appear in Interface Builder as well.</div>
<div> </div>
<div> </div>
<div> </div>
<div>Choose File > New File to create a new file. A window will open containing many file types for you to choose from. For a Cocoa program you would want one of the Cocoa files unless you&#8217;re writing a Cocoa program in Ruby, in which case you would use one of the Ruby files. Name your file and click the Finish button. You&#8217;ve created a subclass file.</div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div><span class="Apple-style-span" style="font-weight: bold;"><br /></span></div>
<div><span class="Apple-style-span" style="font-weight: bold;">Instantiating Your Class</span></div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div></div>
<div>After creating your class in Xcode, you may need to add an instance of your class to the nib file so you can make connections in Interface Builder. If Interface Builder&#8217;s library window is not open, open it by choosing Tools > Library. The library window contains Interface Builder&#8217;s user interface elements.</div>
<div><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_43mxm9V6l5Q/R42eoSkNUFI/AAAAAAAAABU/cEW33LthoG4/s1600-h/LibraryWindow.jpg"><img style="cursor:pointer; cursor:hand;" src="http://2.bp.blogspot.com/_43mxm9V6l5Q/R42eoSkNUFI/AAAAAAAAABU/cEW33LthoG4/s320/LibraryWindow.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5155951563424747602" /></a> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div></div>
<div>Select an NSObject from the library window. NSObject is a blue cube. Drag NSObject to the nib file window. An NSObject named Object should now appear in the nib file window. Choose Tools >Identity Inspector to open the identity inspector. Select the NSObject in the nib file window.</div>
<div> </div>
<div><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_43mxm9V6l5Q/R42exikNUGI/AAAAAAAAABc/G4jBQekyDmM/s1600-h/IdentityInspector.jpg"><img style="cursor:pointer; cursor:hand;" src="http://3.bp.blogspot.com/_43mxm9V6l5Q/R42exikNUGI/AAAAAAAAABc/G4jBQekyDmM/s320/IdentityInspector.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5155951722338537570" /></a></div>
<div> </div>
<div> </div>
<div></div>
<div>The top of identity inspector should have a combo box labeled Class. Choose your class from the list of classes in the combo box. The name of the NSObject instance in the nib file window will change from Object to the name of your class. Any outlets and actions in your class should appear in the identity inspector.</div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div></div>
<div>If your classes are not appearing in Interface Builder, choose File > Synchronize With <span class="blsp-spelling-error" id="SPELLING_ERROR_0">Xcode</span> in Interface Builder.</div>
]]></content:encoded>
			<wfw:commentRss>http://meandmark.com/blog/2008/01/interface-builder-3-change-no-subclass-creation/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
<br />
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /home/szymczyk/public_html/blog/wp-includes/feed-rss2.php:11) in <b>/home/szymczyk/public_html/blog/wp-includes/pluggable.php</b> on line <b>897</b><br />

