<?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>Anima Entertainment GmbH</title>
	<atom:link href="http://www.anima-entertainment.de/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.anima-entertainment.de</link>
	<description>Games Developer</description>
	<lastBuildDate>Mon, 30 Aug 2010 10:00:52 +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>iPhone Programming Part 4 : Audio</title>
		<link>http://www.anima-entertainment.de/?p=248</link>
		<comments>http://www.anima-entertainment.de/?p=248#comments</comments>
		<pubDate>Mon, 30 Aug 2010 10:00:52 +0000</pubDate>
		<dc:creator>Hans Taneli</dc:creator>
				<category><![CDATA[Dev Blog]]></category>

		<guid isPermaLink="false">http://www.anima-entertainment.de/blog/?p=248</guid>
		<description><![CDATA[I want to start talking about how to output audio on iPhone devices. Playing audio on iPhones comes a bit like the arcade apothegm: &#8220;easy to learn but difficult to master&#8221;. Before you start playing audio you should probably know &#8230; <a href="http://www.anima-entertainment.de/?p=248">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I want to start talking about how to output audio on iPhone devices. Playing audio on iPhones comes a bit like the arcade apothegm: &#8220;easy to learn but difficult to master&#8221;. Before you start playing audio you should probably know about some core stuff. In this article I try to introduce some of these basics you should know about. Hopefully with success.<br />
<span id="more-248"></span><br />
First I have to say this article is based on <a href="http://benbritten.com/2008/11/06/openal-sound-on-the-iphone/">this</a> one. </p>
<p>A quick way to force the iPhone doing sound or music stuff is to use the audio system services. To use them in your xcode project simply add the <strong>AudioToolbox Framework</strong> to your application and import the header files:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"> <span style="color: #6e371a;">#import &lt;AudioToolbox/AudioToolbox.h&gt;</span></pre></div></div>

<p>to load and play the sound :</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span> path <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span> pathForResource<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;soundName&quot;</span> ofType<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;caf&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span> afUrl <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> fileURLWithPath<span style="color: #002200;">:</span>path<span style="color: #002200;">&#93;</span>;
UInt32 soundID;
AudioServicesCreateSystemSoundID<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>CFURLRef<span style="color: #002200;">&#41;</span>afUrl,<span style="color: #002200;">&amp;</span>soundID<span style="color: #002200;">&#41;</span>;
AudioServicesPlaySystemSound <span style="color: #002200;">&#40;</span>soundID<span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>Allthough this is good enough to make some UI beeps and blobs you probably want control on preloading files and play them synchronously to an action. On the other hand you want to keep your code as portable as possible? So this seems really like you want to know more about openAL, so lets go through a super quick introduction to it.</p>
<p>There are five consistently appearing terms openAL you may want to know more about :</p>
<ul>
<li>LISTENER</li>
<li>SOURCE</li>
<li>BUFFER</li>
<li>DEVICE</li>
<li>CONTEXT or SESSION</li>
</ul>
<p>The <strong>LISTENER</strong> is you. Any sound the listener can &#8216;hear&#8217; comes out the speakers. OpenAL allows you to specify to place the listener in relation to sources. </p>
<p>The <strong>SOURCE</strong> is something analogous to the speaker. It generates sound which the listener can &#8216;hear&#8217;. Like the listener, you can move the sources around.</p>
<p>The <strong>BUFFER</strong> contains the raw audio data of the sound that will be played.</p>
<p>The <strong>DEVICE</strong> is the actual hardware playing the sound.</p>
<p>The <strong>CONTEXT</strong> or <strong>SESSION</strong> is something like a room containing all the sources and the listener. Metaphorically speaking the sources are musicians the listener is a microphone and the <strong>CONTEXT</strong> is something like <em>air</em> the sound is going through. You will setup positions for listener and sources here and you can specify a category for them:</p>
<ul>
<li><em>kAudioSessionCategory_UserInterfaceSoundEffects</em>:Use this category for sound effects such as touch feedback, explosions, etc.</li>
<li><em>kAudioSessionCategory_AmbientSound</em> : Use this category for backgound sounds such as rain, car engine noise, etc.  Mixes with other music.</li>
<li><em>kAudioSessionCategory_SoloAmbientSound</em> : Use this category for backgound sounds.  Other music will stop playing.</li>
<li><em>kAudioSessionCategory_MediaPlayback</em> : Use this category for music tracks.</li>
<li><em>kAudioSessionCategory_LiveAudio</em> : Use this category for interactive music such as playing an instrument on the screen.</li>
<li><em>kAudioSessionCategory_RecordAudio</em> : Use this category when recording audio.</li>
<li><em>kAudioSessionCategory_PlayAndRecord</em> : Use this category when recording and playing back audio.</li>
</ul>
<p>To get this all work you need five tasks to be done:</p>
<ol>
<li>get the device</li>
<li>make a context with the device</li>
<li>put some data into a buffer</li>
<li>attach the buffer to a source</li>
<li>play the source</li>
</ol>
<p>Audioformats I successfully tested on iPhones OS 2.2.1 and above:</p>
<ul>
<li>.CAF (16-Bit PCM) Not Compressed</li>
<li>.AIF (IMA4 16-Bit PCM) Compressed </li>
</ul>
<p><b>.CAF</b><br />
To convert a audiofile to this format simply open a terminal on your mac and type:</p>

<div class="wp_syntax"><div class="code"><pre class="console" style="font-family:monospace;">usr/bin/afconvert -f caff -d LEI16@44100 inputSoundFile.aiff outputSoundFile.caf</pre></div></div>

<p><b>.AIF</b><br />
To convert an audiofile to this format use export on quicktime pro.</p>
<p>Since this was a quick walkthrough I guess you want to hear more about this stuff and you want to see actual code. Next post will give you all this &#8211; be prepared!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anima-entertainment.de/?feed=rss2&amp;p=248</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Programming Part 3: Properties</title>
		<link>http://www.anima-entertainment.de/?p=244</link>
		<comments>http://www.anima-entertainment.de/?p=244#comments</comments>
		<pubDate>Tue, 10 Aug 2010 12:00:11 +0000</pubDate>
		<dc:creator>Hans Taneli</dc:creator>
				<category><![CDATA[Dev Blog]]></category>

		<guid isPermaLink="false">http://www.anima-entertainment.de/blog/?p=244</guid>
		<description><![CDATA[It might seem quite absurd to focus on simple tasks like getter and setter &#8211; but when I started programming with objective-c it was one thing I did not get at once. Therefore here is an overview in getters and &#8230; <a href="http://www.anima-entertainment.de/?p=244">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It might seem quite absurd to focus on simple tasks like getter and setter &#8211; but when I started programming with objective-c it was one thing I did not get at once. Therefore here is an overview in getters and setter for objective-c.<span id="more-244"></span></p>
<p>In objective-c you can manually write your getter and setter methods or let the compiler do the work. An attribute with getters and / or setters is called &#8220;property&#8221;. </p>
<h3>Manual property creation</h3>

<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">/////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">// File : example1.h</span>
&nbsp;
<span style="color: #a61390;">@interface</span> myClass
<span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">float</span> value;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span> value;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> setValue<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span>_value;
&nbsp;
<span style="color: #a61390;">@end</span>;</pre></td></tr></table></div>


<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">/////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">// File : example1.m</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> myClass
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span> value <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> value;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> setValue<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span>_value <span style="color: #002200;">&#123;</span>
    value <span style="color: #002200;">=</span> _value;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>

<h3>Half automatic property creation</h3>
<p>If you want the compiler to add automatically the getter and setter method in your header file you can declare a property as shown below. Still you can write the content of your getter and setter manually.</p>

<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">/////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">// File : example2.h</span>
&nbsp;
<span style="color: #a61390;">@interface</span> myClass
<span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">float</span> value;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@property</span> <span style="color: #a61390;">float</span> value;
&nbsp;
<span style="color: #a61390;">@end</span>;</pre></td></tr></table></div>


<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">/////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">// File : example2.m</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> myClass
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span> value <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> value;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> setValue<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span>_value <span style="color: #002200;">&#123;</span>
    value <span style="color: #002200;">=</span> _value;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>

<h3>Full automatic property creation</h3>
<p>If you just want a public attribute and don&#8217; want to do some stuff when setting or getting is called you can completely automate the getter and setter &#8211; you can synthesize them. The compiler will make the smallest and fastest code to assign or retrieve the attribute. So in this example, it will just assign the value with one call and return it with one call &#8211; so at the end it shouldn&#8217;t be different to the example above.</p>

<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">/////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">// File : example3.h</span>
<span style="color: #a61390;">@interface</span> myClass
<span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">float</span> value;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@property</span> <span style="color: #a61390;">float</span> value;
&nbsp;
<span style="color: #a61390;">@end</span>;</pre></td></tr></table></div>


<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">/////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">// File : example3.m</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> myClass
<span style="color: #a61390;">@synthesize</span> value;
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>

<h3>Property Declaration Attributes</h3>
<p>There are so called declaration attributes to define how an external object accesses your property and what should happen with the retain count automatically. </p>
<h4>Accessor Method Names</h4>
<p>To specify an accessor name you can use :</p>
<ul>
<li><strong>getter </strong>= &lt;getterName&gt; &#8211; property is readable through the given getterName</li>
<li><strong>setter </strong>= &lt;setterName&gt; &#8211; property is writeable through the giben setterName</li>
</ul>
<h4>Writeability</h4>
<p>To specify read and/or write accessors you can use :</p>
<ul>
<li><strong>readwrite </strong>(default) — property is writeable and readable</li>
<li><strong>readonly </strong>— property is readonly</li>
</ul>
<h4>Setter Semantics</h4>
<p>These attributes specify the semantics of a <strong>set </strong>accessor</p>
<ul>
<li><strong>assign </strong>(default) — Specifies that the setter uses simple assignment.</li>
<li><strong>retain </strong>— Specifies that retain should be invoked on the object upon assignment. The previous value is sent a release message.  This attribute is valid only for Objective-C object types. (You cannot specify retain for Core Foundation objects)</li>
<li><strong>copy </strong>— Specifies that a copy of the object should be used for assignment. The previous value is sent a release message. The copy is made by invoking the copy method. This attribute is valid only for object types, which must implement the NSCopying protocol.</li>
</ul>
<h4>Atomicity (Multithread behaviour)</h4>
<p>This attribute specifies that accessor methods are not atomic (Default is atomic).</p>
<ul>
<li><strong>nonatomic</strong> — Specifies the accessors are not atomic</li>
</ul>
<p>If your accessors are atomic &#8211; which is if you not specify them as nonatomic &#8211; a synthesized getter will look like :</p>

<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>_internal lock<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">// lock using an object-level lock</span>
<span style="color: #a61390;">id</span> result <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>value retain<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>_internal unlock<span style="color: #002200;">&#93;</span>;
<span style="color: #a61390;">return</span> result;</pre></td></tr></table></div>

<p>If you specify nonatomic, then a synthesized accessor for an object property simply returns the value directly.</p>
<h3>Interfacebuilder</h3>
<p>If you want to specify that a property is an Interface Builder outlet, you can use <em>IBOutlet</em> keyword:</p>

<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet <span style="color: #400080;">NSButton</span> <span style="color: #002200;">*</span>myButton;</pre></td></tr></table></div>

<h3>Synthesize</h3>
<p>You can specify a variable to be used for a property:</p>

<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@synthesize</span> firstName, lastName, age <span style="color: #002200;">=</span> yearsOld;</pre></td></tr></table></div>

<h3>Dynamic</h3>
<p>You use the @dynamic keyword to tell the compiler that you will fulfill the API contract implied by a property either by providing method implementations directly or at runtime using other mechanisms such as dynamic loading of code or dynamic method resolution.</p>

<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">/////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">// File : dynamic_example.h</span>
&nbsp;
<span style="color: #a61390;">@interface</span> MyClass <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span>
<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>value;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>copy, readwrite<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>value;
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">/////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">// File : dynamic_example.m</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// assume using garbage collection</span>
<span style="color: #a61390;">@implementation</span> MyClass
@dynamic value;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>value <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> value;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>setValue<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>newValue <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>newValue <span style="color: #002200;">!=</span> value<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        value <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>newValue copy<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>

<h3>Property access</h3>
<p>When you access a property via synthesized dot notation or directly you have to notice the diffrence. If you access a property directly you will not use the accessor methods.</p>

<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">/////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">// File : accessor.h</span>
&nbsp;
<span style="color: #a61390;">@interface</span> MyClass <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">id</span> value;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #a61390;">id</span> value;
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> myMethod;
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">/////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">// File : accessor.m</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;accessor.h&quot;</span>
<span style="color: #a61390;">@implementation</span> MyClass
&nbsp;
<span style="color: #a61390;">@synthesize</span> value;
&nbsp;
<span style="color: #11740a; font-style: italic;">/* synthesize will do something like this :
-(id) value {
    return value;
}
&nbsp;
-(void) setValue:(id) _value {
    [value autorelease];
    [_value retain];
    value = _value;
}
*/</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> myMethod <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span> strValue <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Hello Value&quot;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// this would call the accessor 'setValue:( id );'</span>
    <span style="color: #11740a; font-style: italic;">// which will cause a retain on 'strValue' and a release</span>
    <span style="color: #11740a; font-style: italic;">// of what ever was there before.</span>
    self.value <span style="color: #002200;">=</span> strValue;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// the following call will just do that value now points to 'strValue', </span>
    <span style="color: #11740a; font-style: italic;">// but it does not call any accessor, so there will be no retain or release</span>
    <span style="color: #11740a; font-style: italic;">// message sent.</span>
    value <span style="color: #002200;">=</span> strValue; 
&nbsp;
    <span style="color: #a61390;">id</span> obj <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>; <span style="color: #11740a; font-style: italic;">// just a holder for our object</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// the following line will call the accessor '( id ) value;' which will in</span>
    <span style="color: #11740a; font-style: italic;">// - in this case - do nothing special because the accessor just</span>
    <span style="color: #11740a; font-style: italic;">// returns the object.</span>
    obj <span style="color: #002200;">=</span> self.value; 
&nbsp;
    <span style="color: #11740a; font-style: italic;">// the following line will just do that obj has the same pointer as value</span>
    <span style="color: #11740a; font-style: italic;">// but will not call any accessor.</span>
    obj <span style="color: #002200;">=</span> value;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.anima-entertainment.de/?feed=rss2&amp;p=244</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apple Feature and Top 10</title>
		<link>http://www.anima-entertainment.de/?p=340</link>
		<comments>http://www.anima-entertainment.de/?p=340#comments</comments>
		<pubDate>Sat, 31 Jul 2010 13:34:19 +0000</pubDate>
		<dc:creator>Toby</dc:creator>
				<category><![CDATA[Anima News]]></category>

		<guid isPermaLink="false">http://www.anima-entertainment.de/?p=340</guid>
		<description><![CDATA[We’re happy to announce that Apple liked our game so much that we got a feature in nearly every region worldwide. We also entered the German Top 10 Overall yesterday afternoon and are still working our way up. Check the &#8230; <a href="http://www.anima-entertainment.de/?p=340">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We’re happy to announce that Apple liked our game so much that we got a feature in nearly <strong>every region worldwide</strong>. We also entered the <strong>German Top 10 Overall</strong> yesterday afternoon and are still working our way up. Check the <a href="http://itunes.apple.com/us/app/earth-defender/id381290013" target="_blank"><strong>App Store</strong> </a> and watch the <a href="http://www.youtube.com/watch?v=nigfYp6pxUI" target="_blank"><strong>trailer</strong></a>.</p>
<p>Currently we are at a top position at the <strong>“New and Noteworthy”</strong> category at the German App Store. So far we got splendid average ratings:</p>
<ul>
<li>Germany: 4,5</li>
<li>USA: 4,0</li>
<li>France: 4,5</li>
<li>United Kingdom: 4,5</li>
</ul>
<p>We want to thank all the people how played the game and shared their opinion with us. Thank you very much for the support!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anima-entertainment.de/?feed=rss2&amp;p=340</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Earth Defender is out now!</title>
		<link>http://www.anima-entertainment.de/?p=204</link>
		<comments>http://www.anima-entertainment.de/?p=204#comments</comments>
		<pubDate>Tue, 20 Jul 2010 06:43:30 +0000</pubDate>
		<dc:creator>Toby</dc:creator>
				<category><![CDATA[Anima News]]></category>

		<guid isPermaLink="false">http://www.anima-entertainment.de/blog/?p=204</guid>
		<description><![CDATA[Right now our brand new action title Earth Defender is hitting the Apple Appstore worldwide – get it now! Check out the brand new trailer. For marketing and publishing we teamed up with the worlds leading mobile games developer and &#8230; <a href="http://www.anima-entertainment.de/?p=204">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Right now our brand new action title <strong>Earth Defender</strong> is hitting the <a href="http://itunes.apple.com/us/app/earth-defender/id381290013?mt=8" target="_blank"><strong>Apple Appstore</strong></a> worldwide – <a href="http://itunes.apple.com/us/app/earth-defender/id381290013" target="_blank">get it now</a>! Check out the brand new <a href="http://www.youtube.com/watch?v=nigfYp6pxUI" target="_blank">trailer</a>.</p>
<p>For marketing and publishing we teamed up with the worlds leading mobile games developer and publisher <a title="Fishlabs Entertainment" href="http://www.fishlabs.net" target="_blank"><strong>Fishlabs Entertainment</strong></a> &#8211; to push our game to the next level.</p>
<p>Get ready for a whole new action packed arcade game: Defend the Earth against hordes of aliens and mighty boss ships. To face the large variety of hostiles, you are armed with a powerful arsenal of blast bombs, all-devouring black hole bombs and lightning bombs. Skillfully placed, their explosions combine to gigantic chain reactions blowing up everything in reach. Stunning high detail graphics, a scenic orchestral score, innovative multi-touch mechanics and heart-stopping game play deliver a whole-new spin on the space-action genre &#8211; for veterans and rookies alike. Join the location based <strong>OpenFeint</strong> leader boards and share your score via Facebook and Twitter.</p>
<p><a href="http://itunes.apple.com/us/app/earth-defender/id381290013?mt=8" target="_blank">Download</a><strong> </strong><strong>Earth Defender</strong> now to your iPhone™ , iPod touch™ and iPad™</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anima-entertainment.de/?feed=rss2&amp;p=204</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Programming Part 2 : Objective C Memory Management</title>
		<link>http://www.anima-entertainment.de/?p=242</link>
		<comments>http://www.anima-entertainment.de/?p=242#comments</comments>
		<pubDate>Tue, 29 Jun 2010 08:18:13 +0000</pubDate>
		<dc:creator>Hans Taneli</dc:creator>
				<category><![CDATA[Dev Blog]]></category>

		<guid isPermaLink="false">http://www.anima-entertainment.de/blog/?p=242</guid>
		<description><![CDATA[In your application you should always know about when objects are allocated and when they will be released, otherwise your application will crash or have memory leaks, which will on low memory systems like iPhone 3G and earlier lead also &#8230; <a href="http://www.anima-entertainment.de/?p=242">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In your application you should always know about when objects are allocated and when they will be released, otherwise your application will crash or have memory leaks, which will on low memory systems like iPhone 3G and earlier lead also to an application crash. <span id="more-242"></span></p>
<p>There are two possibillities how to handle object instances. The first way is to  manually allocate and release objects. The other -more tempting- way is to let the system release it for you, but then sometimes your application will hang or temporarly stick in memory.</p>
<p>The creators of Objective C may thought : &#8220;Why not combine both techniques to get benefits of both of it?&#8221;. Well, sometimes I think they may have missed the goal. If you are not following strictly the rules objects are deallocated when you don&#8217;t want it, and sometimes they will be deallocated twice, which both results in an application crash. Or never the less they won&#8217;t be deallocated ever, so it results in memory leaks (which could end the application on iPhones with : result 101)</p>
<p>But how does an auto-release function (generally spoken)? All objects derived from a general object will have the ability to count the references. If you create an object the reference will be 1. If you assign this object to another variable the reference counter will be increased by one. If you reset this variable to any other object (also NULL, nil, or what ever) the reference counter will be decreased by one. If all references are lost (reference counter is zero) the object is not referenced anymore and will be released by the system (e.g. garbage collector).</p>
<p>In objective-c this is done by the NSObject class. But with a tiny but huge difference &#8211; if you assign an object to a variable the retain counter will only be increased / decreased if you use a so called retain-property. I will discuss this later.</p>
<p>Therefore our focus is about these methods of <em>NSObject</em>:</p>
<div style="float: left; width: 100%; margin-top: 10px; margin-bottom: 10px;">
<div style="float: left; width: 45em;">
<div style="border: 1px solid black; border-right:0px;padding: 2px; height: 3em; float: left; width: 10em;"><strong>alloc</strong></div>
<div style="border: 1px solid black; padding: 2px; height: 3em; float: left; width: 30em;">allocates the necessary memory for a new object and returns it with a reference count of one.</div>
<div style="border: 1px solid black; border-top:0px;border-right:0px;padding: 2px; height: 2em; float: left; width: 10em;"><strong>release</strong></div>
<div style="border: 1px solid black; border-top:0px;padding: 2px; height: 2em; float: left; width: 30em;">Decreases the receiver&#8217;s reference count by one.</div>
<div style="border: 1px solid black; border-top:0px;border-right:0px;padding: 2px; height: 6em; float: left; width: 10em;"><strong>autorelease</strong></div>
<div style="border: 1px solid black; border-top:0px;padding: 2px; height: 6em; float: left; width: 30em;">Adds the receiver to the application&#8217;s autorelease pool, which will decrease the receiver&#8217;s reference count by &#8220;1&#8243; (<em>at some point in the future</em>) . Autorelease is much slower than release, so use it wisely.</div>
<div style="border: 1px solid black; border-top:0px;border-right:0px;padding: 2px; height: 2em; float: left; width: 10em;"><strong>retain</strong></div>
<div style="border: 1px solid black; border-top:0px;padding: 2px; height: 2em; float: left; width: 30em;">Increases the receiver&#8217;s reference count by one.</div>
<div style="border: 1px solid black; border-top:0px;border-right:0px;padding: 2px; height: 3em; float: left; width: 10em;"><strong>copy</strong></div>
<div style="border: 1px solid black; border-top:0px;padding: 2px; height: 3em; float: left; width: 30em;">Makes a copy of an object, and returns it with retain count of one.</div>
</div>
</div>
<h4><strong>Example 1</strong></h4>
<p>Objects you allocate with <em>alloc </em>should be released with <em>release</em> and then grounded to <em>nil</em>.</p>

<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>myMethod
<span style="color: #002200;">&#123;</span>
    MyClass <span style="color: #002200;">*</span> myObject;
    myObject<span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>MyClass alloc<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Do stuff</span>
&nbsp;
    <span style="color: #002200;">&#91;</span>myObject release<span style="color: #002200;">&#93;</span>;
    myObject <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>If you don&#8217;t want to release your objects manually you could make the use of an <em>autorelease pool</em>. If you send the <em>autorelease </em>message to an object it will be sent and added to the <em>autorelease pool</em>. At the end of an event loop, this <em>autorelease pools</em> is released by the application object and then all of the objects contained within it are released, too. At the beginning of the next loop, a new pool is created and so on. You should keep track of your instances if you use multithreading. The default autorelease pool is linked to the main loop thread &#8211; so if you use another thread make sure you use your own autorelease pool &#8211; or even better: just dont use autorelease.</p>
<h4><strong>Example 2</strong></h4>
<p>An autoreleased Object is considered to be valid whithin the scope where it received the <em>autorelease </em>message.</p>

<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>myMethod
<span style="color: #002200;">&#123;</span>
    MyClass <span style="color: #002200;">*</span> myObject;
    myObject <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>MyClass alloc<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>myObject autorelease<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// myObject will be valid until</span>
    <span style="color: #11740a; font-style: italic;">// the very end of this method!</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<h4><strong>Example 3</strong></h4>
<p>When you have a method that creates and returns an object autorelease is quite useful to make sure that an object will be released on time.</p>

<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>myFunction
<span style="color: #002200;">&#123;</span>
&nbsp;
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>myString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> alloc<span style="color: #002200;">&#93;</span> initWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Hello String.&quot;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>myString autorelease<span style="color: #002200;">&#93;</span>;  <span style="color: #11740a; font-style: italic;">// we have to do this to prevent a memory leak</span>
    <span style="color: #a61390;">return</span> myString;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<h4><strong>Example 4<br />
</strong></h4>
<p>There are so named <em>convencience constructors</em> which will return <em>autoreleased </em>objects. If you use them and you want to keep them at the end of a method block, you have to sent a <em>retain</em> message. So if you keept in mind to call <em>release </em>or <em>autorelease </em>for each <em>alloc</em>, you know have to complete the rule to : <em>for each alloc and for each retain you have to call release or autorelease</em>.</p>

<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// if we assume that myVar exists</span>
myVar <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithCString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">&quot;Hello String.&quot;</span><span style="color: #002200;">&#93;</span> retain<span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p>So we can breakdown the memory management for objective-c to some rules :</p>
<h3><span>Rule 1 : Retention Count<br />
</span></h3>
<ol>
<li><span>Within a given block, the use of -<em>copy</em>, -<em>alloc </em>and -<em>retain </em>should be equal the use of -<em>release</em> and -<em>autorelease</em>.</span></li>
<li><span>Objects created using <em>convenience cunstructors</em> (e.g. NSString&#8217;s strintWithCString) are concidered <em>autoreleased</em>.</span></li>
<li><span>Implement a -<em>dealloc </em>method to release the instance variables you own.</span></li>
</ol>
<h4>Example 1: alloc and release</h4>

<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>printHello
<span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">string</span>;
	<span style="color: #a61390;">string</span> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> alloc<span style="color: #002200;">&#93;</span> initWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Hello&quot;</span><span style="color: #002200;">&#93;</span>;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #a61390;">string</span><span style="color: #002200;">&#41;</span>;
	<span style="color: #11740a; font-style: italic;">// we created string with alloc -- release it</span>
	<span style="color: #002200;">&#91;</span><span style="color: #a61390;">string</span> release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<h4>Example 2: Convenience constructor</h4>

<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> printHello
<span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">string</span>;
	<span style="color: #a61390;">string</span> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Hello&quot;</span><span style="color: #002200;">&#93;</span>;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #a61390;">string</span><span style="color: #002200;">&#41;</span>;
	<span style="color: #11740a; font-style: italic;">// we created string with convenience constructor</span>
	<span style="color: #11740a; font-style: italic;">// we can assume it's autoreleased</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<h3><span>Rule 2 : Always use accessor methods<br />
</span></h3>
<p>If you are using retain and release on a classes instance variables throughout your code, you are almost certainly doing the wrong thing. Use conistently accessor methods of classes to decrease memory management problems. </p>
<h4>Example</h4>

<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> Counter <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span>
<span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSNumber</span> <span style="color: #002200;">*</span>count;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSNumber</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>count
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> count;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>setCount<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSNumber</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>newCount
<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>newCount retain<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>count release<span style="color: #002200;">&#93;</span>;
	count <span style="color: #002200;">=</span> newCount;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>dealloc
<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>self setCount<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>reset
<span style="color: #002200;">&#123;</span>
<span style="color: #11740a; font-style: italic;">//*/</span>
<span style="color: #11740a; font-style: italic;">//    YOU COULD DO :</span>
	<span style="color: #400080;">NSNumber</span> <span style="color: #002200;">*</span>zero <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNumber</span> numberWithInt<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>self setCount<span style="color: #002200;">:</span>zero<span style="color: #002200;">&#93;</span>;
<span style="color: #11740a; font-style: italic;">/*/
//    OR (if you have to alloc here) :
	NSNumber *zero = [[NSNumber alloc] initWithInt:0];
	[self setCount:zero];
	[zero release];
//*/</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<h3><span>Rule 2 : NSArray, NSDictionary, NSSet etc.<br />
</span></h3>
<p>When you add an object to a collection class the collection retains it. A release message will be sent when the collection it self gets released. To understand this, think of what would you do if you are planning a collection class. You wanted to make sure that no objects you were given to look after disappeared out from under you else where, so you send them a <code>-retain </code>message as they&#8217;re passed in. If they&#8217;re removed, you have to send a balancing <code>-release</code> message. Same when your collection will be released, any remaining objects in your collection should be sent a <code>-release</code> message during your own <code>-dealloc</code> method.</p>
<p>The following examples are both correct.</p>
<h4>Example 1</h4>

<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> myMethod
<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSMutableArray</span> <span style="color: #002200;">*</span>array;
    <span style="color: #a61390;">int</span> i;
    <span style="color: #11740a; font-style: italic;">// ...</span>
    <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span>i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i <span style="color: #002200;">&amp;</span>lt; <span style="color: #2400d9;">10</span>; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
        <span style="color: #400080;">NSNumber</span> <span style="color: #002200;">*</span>n <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNumber</span> numberWithInt<span style="color: #002200;">:</span> i<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#91;</span>array addObject<span style="color: #002200;">:</span> n<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<h4>Example 2</h4>

<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> myMethod
<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSMutableArray</span> <span style="color: #002200;">*</span>array;
    <span style="color: #a61390;">int</span> i;
    <span style="color: #11740a; font-style: italic;">// ...</span>
    <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span>i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i <span style="color: #002200;">&amp;</span>lt; <span style="color: #2400d9;">10</span>; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
        <span style="color: #400080;">NSNumber</span> <span style="color: #002200;">*</span>n <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNumber</span> alloc<span style="color: #002200;">&#93;</span> initWithInt<span style="color: #002200;">:</span> i<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#91;</span>array addObject<span style="color: #002200;">:</span> n<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#91;</span>n release<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<h3><span>Release and dealloc<br />
</span></h3>
<p>The release message will be sent by you or by an autorelease pool. The release method of an object decreases the reference counter by one, and if its zero calls the dealloc method.</p>
<h3>Vicious retain circles</h3>
<p>Guess we have an object A is retaining object B and object B is retaining object A. Now these objects never reach a zero retain count. Just in that moment the reference count gets to one, they are effectively out of the program. This is called <em>vicious retain circles</em> and it is possible to have very complex retain cirules like that where the minumum count is even higher than one. To avoid this you should always plan your class dependency wisely. Lets take a look on the Cocoa view hierachy. A NSView can have several subviews which have subviews and so on. On the other side a NSView has also a pointer to the superview. Why doesn&#8217;t this ends in an vicious retain circle?  Well, NSViews retains their subviews but not their superview.<br />
<br/></p>
<h3><span>Nonatomic vs Atomic</span></h3>
<p>If you define properties you will often see this :</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span> nonatomic, retain <span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span> myString;</pre></div></div>

<p>If you dont use <b>nonatomic</b> the default would be <b>atomic</b>. But what does this thing do? If you write your own accessors rather than using synthesized ones the property will do nothing. If you use synthesized properties, atomic properties are like <i>synchronized</i> attributes in java &#8211; they will do an object-level lock to ensure that only one thread is able to read or write this property. This doesn&#8217;t mean the whole object is thread-safe, but the property reads/writes are. Even if you still think: &#8220;Hell yeah! I want it!&#8221; you should know that this is in cost of performance &#8211; so in most cases nonatomic properties are faster. </p>
<p><br/></p>
<h3><span>Further Links<br />
</span></h3>
<ul>
<li>Documentation on developer.apple.com : <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html">Memory Managemet</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.anima-entertainment.de/?feed=rss2&amp;p=242</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Programming Part 1</title>
		<link>http://www.anima-entertainment.de/?p=214</link>
		<comments>http://www.anima-entertainment.de/?p=214#comments</comments>
		<pubDate>Tue, 22 Jun 2010 14:18:34 +0000</pubDate>
		<dc:creator>Hans Taneli</dc:creator>
				<category><![CDATA[Dev Blog]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[ObjectiveC]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://www.anima-entertainment.de/blog/?p=214</guid>
		<description><![CDATA[When I started developing iPhone applications a mayor problem was to understand some technical terms like what the hell is XCode, Cocoa or Objective C. So here first some very short descriptions the the most wanted terms in iPhone programming. &#8230; <a href="http://www.anima-entertainment.de/?p=214">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When I started developing iPhone applications a mayor problem was to understand some technical terms like what the hell is XCode, Cocoa or Objective C. So here first some very short descriptions the the most wanted terms in iPhone programming.<br />
<span id="more-214"></span><br />
<strong>XCode</strong> : Like Visual Studio for Microsoft Windows is XCode a programming plattform to code applications for Apple Mac OS Systems &#8211; keep in mind that iPhones are running Mac OS, too.</p>
<p><strong>Cocoa</strong> : some may think it&#8217;s a pendant to java ( like java was coffee, so cocoa have to be something like coffee for children: cocoa) &#8211; but its not! It&#8217;s a huge coding library (API) to code your mac applictions. Cocoa classes are starting with &#8220;NS&#8221;-Tag, like NSString, or NSObject.</p>
<p><strong>Objective C </strong>: Objective C, or short ObjC is a programming language extended from standard C. So all standard C code is leagal Objective C code. If you already read something about objective C you probably ask your self what the heck is that thing about these brackets &#8220;[ ]&#8221; ? Here is a simple code snippet which we will discuss later:</p>

<div class="wp_syntax"><table><colgroup><col width="5%" /><col width="95%" /> </colgroup><tr ><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">///////////////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">// FILE : classA.h</span>
<span style="color: #11740a; font-style: italic;">// Header File for classA</span>
<span style="color: #11740a; font-style: italic;">///////////////////////////////////////////</span>
<span style="color: #6e371a;">#import &lt;uikit /UIKit.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> classA <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> <span style="color: #002200;">&#123;</span>
 bool myBoolean;
 <span style="color: #a61390;">int</span> myNumber;
 <span style="color: #a61390;">int</span> myIdentifier;
 <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span> name;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// manual creating getters and setters for a property</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> myNumber;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> setMyNumber<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>value;
&nbsp;
<span style="color: #11740a; font-style: italic;">// automatic creating getters and setters for a property</span>
<span style="color: #a61390;">@property</span> bool myBoolean;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>readonly<span style="color: #002200;">&#41;</span> <span style="color: #a61390;">int</span> myIdentifier;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>assign<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span> name;
&nbsp;
<span style="color: #11740a; font-style: italic;">// methods and functions</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> doStuffWithA<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>bool<span style="color: #002200;">&#41;</span>a B<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>b C<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>c;
&nbsp;
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">///////////////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">// FILE : classA.m</span>
<span style="color: #11740a; font-style: italic;">// Implementation File for classA</span>
<span style="color: #11740a; font-style: italic;">///////////////////////////////////////////</span>
<span style="color: #a61390;">@implementation</span> classA
&nbsp;
<span style="color: #11740a; font-style: italic;">// automatic generation of getters and setters for properties:</span>
<span style="color: #a61390;">@synthesize</span> myBoolean;
<span style="color: #a61390;">@synthesize</span> myIdentifier;
<span style="color: #a61390;">@synthesize</span> name;
&nbsp;
<span style="color: #11740a; font-style: italic;">// manual getter and setter methods:</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> setMyNumber<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>value <span style="color: #002200;">&#123;</span>
 myNumber <span style="color: #002200;">=</span> value;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> myNumber <span style="color: #002200;">&#123;</span>
 <span style="color: #a61390;">return</span> myNumber;
 <span style="color: #11740a; font-style: italic;">// this is ok. It will return the value. To call the function in ObjC</span>
 <span style="color: #11740a; font-style: italic;">// you have to write something like:&quot;return [self myNumber];&quot;</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> doStuffWithA<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>bool<span style="color: #002200;">&#41;</span>a B<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>b C<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>c <span style="color: #002200;">&#123;</span>
 myBoolean <span style="color: #002200;">=</span> a;
 myNumber <span style="color: #002200;">=</span> b;
 myName <span style="color: #002200;">=</span> c;
 myIdentifier <span style="color: #002200;">=</span> b; <span style="color: #11740a; font-style: italic;">// ok, internal writeable - only external readonly</span>
 <span style="color: #11740a; font-style: italic;">// not allowed:  self.myNumber = b;</span>
 <span style="color: #11740a; font-style: italic;">// dot notations are only allowed for automatic generated properties.</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">///////////////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">// FILE main.m</span>
<span style="color: #11740a; font-style: italic;">// Main Application File</span>
<span style="color: #11740a; font-style: italic;">///////////////////////////////////////////</span>
<span style="color: #6e371a;">#import &lt;/uikit&gt;&lt;uikit /UIKit.h&gt;</span>
<span style="color: #6e371a;">#import &quot;classA.h&quot;</span>
&nbsp;
<span style="color: #a61390;">int</span> main<span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> argc, <span style="color: #a61390;">char</span> <span style="color: #002200;">*</span>argv<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
  classA <span style="color: #002200;">*</span> myObject <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>classA alloc<span style="color: #002200;">&#93;</span>init<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>myObject setMyNumber<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">// ok</span>
  <span style="color: #a61390;">int</span> a <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>myObject myNumber<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">// ok</span>
  <span style="color: #11740a; font-style: italic;">// myObject.setNumber(1); // not allowed.</span>
  <span style="color: #11740a; font-style: italic;">// int a = myObject.myNumber; // only on automatic generated properties.</span>
  <span style="color: #002200;">&#91;</span>myObject setMyBoolean<span style="color: #002200;">:</span><span style="color: #a61390;">true</span><span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">// ok</span>
  myObject.myBoolean <span style="color: #002200;">=</span> <span style="color: #a61390;">true</span>; <span style="color: #11740a; font-style: italic;">// ok</span>
  bool b <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>myObject myBoolean<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">// ok</span>
  b <span style="color: #002200;">=</span> myObject.myBoolean; <span style="color: #11740a; font-style: italic;">// ok</span>
  <span style="color: #11740a; font-style: italic;">// [myObject setMyIdentifier:1]; // not allowed : readonly</span>
  <span style="color: #11740a; font-style: italic;">// myObject.myIdentifier = 1; // not allowed : readonly</span>
  <span style="color: #a61390;">int</span> i <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>myObject myIdentifier<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">// ok</span>
  i <span style="color: #002200;">=</span> myObject.myIdentifier; <span style="color: #11740a; font-style: italic;">// ok</span>
  <span style="color: #002200;">&#91;</span>myObject doStuffWithA<span style="color: #002200;">:</span><span style="color: #a61390;">true</span> B<span style="color: #002200;">:</span><span style="color: #2400d9;">42</span> C<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Text&quot;</span><span style="color: #002200;">&#93;</span>;  
&nbsp;
 <span style="color: #a61390;">return</span> retVal;
<span style="color: #002200;">&#125;</span>
&lt;<span style="color: #002200;">/</span>uikit&gt;</pre></td></tr></table></div>

<p>Some words about this &#8220;[ ]&#8221; &#8211; stuff. First of all, in Objective C you do not call a member function of an object directly (like &#8220;object.methodName(value1, value2)&#8221;. You retain a controller to sent a message to the object by using these brackets ( [object methodName:value1 param2Name: value2] ).</p>
<p>The basic form is [object param1Name:value1 param2Name:value2 param3Name:value3] where param1Name is the method name itself. That&#8217;s why we called our &#8220;doStuff&#8221; method in classA :  &#8220;doStuffWithA&#8221;. When you call that method it would be read like [doStuffWith<strong>A</strong>:true <strong>B</strong>:42 <strong>C</strong>:@"String"].</p>
<p>Now some may think that Objective C is a bit ugly. You are right &#8211; it&#8217;s ugly. But never the less it <strong>is</strong> a powerful tool, so it&#8217;s worth to get through it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anima-entertainment.de/?feed=rss2&amp;p=214</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
