<?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>musicalgeometry &#187; Objective-C</title>
	<atom:link href="http://www.musicalgeometry.com/archives/category/objective-c/feed" rel="self" type="application/rss+xml" />
	<link>http://www.musicalgeometry.com</link>
	<description>sound, code, &#38; DIY tech</description>
	<lastBuildDate>Sat, 24 Jul 2010 16:32:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Plug-And-Play OpenAL / AVFoundation Sound Engine For iPhone Apps</title>
		<link>http://www.musicalgeometry.com/archives/912</link>
		<comments>http://www.musicalgeometry.com/archives/912#comments</comments>
		<pubDate>Thu, 25 Feb 2010 21:17:47 +0000</pubDate>
		<dc:creator>Jason Job</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[sound]]></category>

		<guid isPermaLink="false">http://www.musicalgeometry.com/?p=912</guid>
		<description><![CDATA[I recently found a great sound engine for iPhone applications that is pretty much plug-and-play. This sound engine was written by Alex Restrepo under a creative commons attribution-share alike licence, so you are free to use it so long as &#8230; <a href="http://www.musicalgeometry.com/archives/912">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently found a great sound engine for iPhone applications that is pretty much plug-and-play.</p>
<div id="attachment_913" class="wp-caption alignnone" style="width: 510px"><a href="http://www.musicalgeometry.com/wp-content/uploads/2010/02/openal.jpg"><img class="size-full wp-image-913 " style="border: 1px solid black;" title="openal" src="http://www.musicalgeometry.com/wp-content/uploads/2010/02/openal.jpg" alt="" width="500" height="268" /></a><p class="wp-caption-text">OpenAL lets you play multiple sounds at once</p></div>
<p>This sound engine was written by <a href="http://homepage.mac.com/alexrestrepo/indexmain.html">Alex Restrepo</a> under a creative commons attribution-share alike licence, so you are free to use it so long as you attribute the code to the author and if you change it and share it you must do so under the same license.  I have corrected one small mistake (a semi-colon where it should not have been) and also edited the formatting of the code to my personal preference. You can get an Xcode example project that uses the sound engine <a href="http://www.jasonjob.net/share/SoundEngineExample.zip">here</a>. If you just want the sound engine itself you can get it <a href="http://www.jasonjob.net/share/SoundEngine.zip">here</a>.  If you look at the <a href="http://www.jasonjob.net/share/SoundEngineExample.zip">example project</a> you will see how easy this sound engine is to use. It provides simple methods for playing and managing background music and for playing sound effects on top. These classes use AVFoundation to play the background music and OpenAL to play other sounds on top. I am not informed enough about either of these to know what advantages or disadvantages this may offer but will look into it and possibly do a pure OpenAL version.  To add the sound engine to your own project just add the class files included in <a href="http://www.jasonjob.net/share/SoundEngine.zip">SoundEngine.zip</a> to your project. Also be sure to add the OpenAL.framework, AVFoundation.framework and the AudioToolbox.framework otherwise you will get a host of strange errors.  You have the option of using the CMOpenALSoundManager as a singleton. If you do use it as a singleton (you can do this by setting USE_AS_SINGLETON to 1 at the top of CMOpenALSoundManager.h) you just need to initialize it somewhere in your code with:</p>
<pre><code>[[CMOpenALSoundManager sharedCMOpenALSoundManager] init];</code></pre>
<p>You also need to enumerate the tags for your sounds (ideally somewhere that every class that needs them will have access to them):</p>
<pre><code>enum mySoundIds {
BUTTONSOUND1
        BUTTONSOUND2
        SUCCESSSOUND
        ERRORSOUND
};</code></pre>
<p>You can then add your sound effects by passing an array of sound file names like so:</p>
<pre><code>[CMOpenALSoundManager sharedCMOpenALSoundManager].soundFileNames = mySoundFileNamesArray;</code></pre>
<p>To access your sound manager from anywhere in your project make sure you have included the CMOpenSoundManager header file and then reference the sound manager with:</p>
<pre><code>[CMOpenALSoundManager sharedCMOpenALSoundManager]</code></pre>
<p>Here is an example of playing some background music and then playing a sound effect:</p>
<pre><code>[[CMOpenALSoundManager sharedCMOpenALSoundManager] playBackgroundMusic:@"backgroundLoop.m4a"];
[[CMOpenALSoundManager sharedCMOpenALSoundManager] playSoundWithID:BUTTONSOUND1];</code></pre>
<p>One thing that I am not satisfied about with this system is the need for the enumeration. The reason being that you need to know which order the sounds are going to be loaded so that the correct sounds match the correct enum value. A better way in my opinion would be to use NSString keys, so that when you load a sound, you also pass a key. This is the approach taken in the code on the <a href="http://www.gehacktes.net/2009/03/iphone-programming-part-6-multiple-sounds-with-openal/">gethacktes.net</a> blog, which is another great resource for OpenAL on the iPhone. Doing it this way allows you to lazy load sounds in any order. If I make that change I will be sure to post it here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.musicalgeometry.com/archives/912/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xcode Script For Creating Properties From Instance Variables For UIViewController</title>
		<link>http://www.musicalgeometry.com/archives/904</link>
		<comments>http://www.musicalgeometry.com/archives/904#comments</comments>
		<pubDate>Wed, 24 Feb 2010 07:26:29 +0000</pubDate>
		<dc:creator>Jason Job</dc:creator>
				<category><![CDATA[OSX]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[XCode]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.musicalgeometry.com/?p=904</guid>
		<description><![CDATA[One of my favourite blogs on the net is Matt Gallagher&#8217;s Cocoa with Love. Today I was investigating ways to speed up my workflow in Xcode and I found a great mixed Perl and AppleScript script already written by Matt a &#8230; <a href="http://www.musicalgeometry.com/archives/904">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of my favourite blogs on the net is Matt Gallagher&#8217;s <a href="http://cocoawithlove.com/">Cocoa with Love</a>. Today I was investigating ways to speed up my workflow in Xcode and I found a great mixed Perl and AppleScript script already written by Matt a couple of years ago.</p>
<div id="attachment_905" class="wp-caption alignnone" style="width: 637px"><a href="http://cocoawithlove.com/"><img class="size-full wp-image-905 " style="border: 1px solid black;" title="cocoawithlove" src="http://www.musicalgeometry.com/wp-content/uploads/2010/02/cocoawithlove.png" alt="" width="627" height="139" /></a><p class="wp-caption-text">A fantastic resource for Cocoa, Objective-C and programming in general</p></div>
<p>The script called <a href="http://projectswithlove.com/projects/PropertyFromInstanceVariable.zip">PropertyFromInstanceVariable</a> had already been added to by a couple of other people, Yung-Luen Lan &amp; <a href="http://github.com/mschrag/xcode_property_from_ivar">Mike Schrag</a> and <a href="http://www.bernard-web.com/pierre/blog/">Pierre Bernard</a> and I have now shaped it for my own specific needs, and possibly yours too.</p>
<p>The tedium I was trying to eliminate was the process of creating Objective-C properties from instance variables and doing basic memory management on them. This is a repetitive process that seems more appropriate to hand off to the machine.</p>
<p>Matt&#8217;s script allows you to take an instance variable defined in your interface file and automatically create a property for it, synthesize the property in the implementation, add a release statement and set the property to NULL in the dealloc method.</p>
<p>For example, running the script on this:</p>
<pre><code>NSString *myString;</code></pre>
<p>would automatically create this in the interface:</p>
<pre><code>@property (nonatomic, retain) NSString *myString;</code></pre>
<p>this at the top of the implementation:</p>
<pre><code>@synthesize myString;</code></pre>
<p>and adds these two lines to the dealloc method:</p>
<pre><code>[myString release];
myString = NULL;</code></pre>
<p>Because this script was written before the viewDidUnload method had been added to the UIViewController class it didn&#8217;t make use of the viewDidUnload method. I wanted to update it to set the retaining references to subviews in the view hierarchy to nil. These reference properties may have been set through IBOutlets when loading a nib or programmatically in the loadView method.</p>
<p>I have now modified the script to reflect my own coding habits. It still creates the property, synthesizes it and adds a release to the dealloc method, but if the class is a subclass of UIViewController then this is placed in viewDidUnload like so:</p>
<pre><code>self.myString = nil;</code></pre>
<p>This script can be run on multiple instance variables at once and greatly cuts down on the time it takes to set up a new class. Instructions on installing the script can be found <a href="http://cocoawithlove.com/2008/12/instance-variable-to-synthesized.html">here</a>.</p>
<p>You can get my fork of the script on <a href="http://github.com/jj0b/xcode_property_from_ivar">github</a>.</p>
<p>NOTE: I have updated to script and edited this post to reflect those changes. All links are to the most recent version.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.musicalgeometry.com/archives/904/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>When To Use self.myObject Instead Of myObject In iPhone Programming</title>
		<link>http://www.musicalgeometry.com/archives/872</link>
		<comments>http://www.musicalgeometry.com/archives/872#comments</comments>
		<pubDate>Mon, 25 Jan 2010 18:36:52 +0000</pubDate>
		<dc:creator>Jason Job</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.musicalgeometry.com/?p=872</guid>
		<description><![CDATA[I have seen a lot of confusion on the topic of when and why to reference an object using self.myObject versus just plain myObject. It took me a while to understand this myself, and please, if I am mistaken in &#8230; <a href="http://www.musicalgeometry.com/archives/872">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have seen a lot of confusion on the topic of when and why to reference an object using self.myObject versus just plain myObject. It took me a while to understand this myself, and please, if I am mistaken in my explanation, set me right, but here it is as I understand it.</p>
<div id="attachment_878" class="wp-caption alignnone" style="width: 310px"><a href="http://www.musicalgeometry.com/wp-content/uploads/2010/01/objective_c.jpg"><img class="size-medium wp-image-878 " style="border: 1px solid black;" title="objective_c" src="http://www.musicalgeometry.com/wp-content/uploads/2010/01/objective_c-300x225.jpg" alt="" width="300" height="225" /></a><p class="wp-caption-text">Apparently some people don&#39;t like Objective-C</p></div>
<p>If you reference an object in your implementation that you declared in your header with @property and then used @synthesize in your implementation to automatically create getter and setter methods for the object, then using self.myObject  = newObject will call the setter and references to self.myObject will call the getter. As far as I know, if you are just referencing your object you don&#8217;t need to use the getter unless you are trying to distinguish from an object with the same name. When you assign your object however, the distinction becomes very important because everywhere you write:</p>
<pre><code>self.myObject = newObject;</code></pre>
<p>you are actually sending the message:</p>
<pre><code>[self setMyObject:newObject];</code></pre>
<p>which under the hood looks like:</p>
<pre><code>objc_msgSend(self, @selector(setMyObject:), newObject);</code></pre>
<p>The consequence of using self.myObject in this way is that myObject will use whatever retain property you set in the @property declaration. So if you set up myObject like so:</p>
<pre><code>@property (nonatomic, retain) MyObjectClass *myObject;</code></pre>
<p>then the value of myObject will be retained even after newObject has been deallocated.</p>
<p>If instead you had assigned myObject like this:</p>
<pre><code>myObject = newObject;</code></pre>
<p>then myObject is just the same as newObject. Therefore if newObject is deallocated then myObject will be pointing to a meaningless memory address. Probably not what you want.</p>
<p>So, here is an example:</p>
<pre><code>.h file
...
UIView *myUIView;
...
@property (nonatomic, retain) UIView *myUIView;
...

.m file
...
@synthesize myUIView;
...
// Get frame:
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];

// Set up myUIView:
UIView *tempUIView = [[UIView alloc] initWithFrame:applicationFrame];
tempUIView.backgroundColor = [UIColor blackColor];
self.myUIView = tempUIView;
[tempUIView release];
...</code></pre>
<p>At this point in the code myUIView is now set up and ready to use. Because I used the setter to assign myUIView it is unaffected when I release tempUIView. If I had forgotten to use self.myUIView for the assignment then I would be unable to use myUIView later in the program.</p>
<p>Hope that clears things up for some of you. Please comment if I have something wrong or if you can help make things even clearer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.musicalgeometry.com/archives/872/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
