<?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>programming with passion &#187; Objective-C</title>
	<atom:link href="http://www.jasonrowland.com/category/objectivec/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jasonrowland.com</link>
	<description>Learning Mac, Ruby, iPhone, BlackBerry, Android, WinMobile</description>
	<lastBuildDate>Tue, 14 Jun 2011 19:11:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>code sign error The identity doesn&#8217;t match any valid certificate</title>
		<link>http://www.jasonrowland.com/2009/08/code-sign-error-the-identity-doesnt-match-any-valid-certificate/</link>
		<comments>http://www.jasonrowland.com/2009/08/code-sign-error-the-identity-doesnt-match-any-valid-certificate/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 07:31:51 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://www.jasonrowland.com/?p=89</guid>
		<description><![CDATA[I am currently going through some tutorials for the SIO2 game engine I am currently evaluating.  I was able to run the code just fine on my iPhone simulator.  When I went to deploy this tutorial to my iPhone device, I got a &#8220;Code Sign error: The identity &#8216;iPhone Developer: Romain Marucchi-Foino (VC824XU999)&#8217; doesn&#8217;t match [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently going through some tutorials for the SIO2 game engine I am currently evaluating.  I was able to run the code just fine on my iPhone simulator.  When I went to deploy this tutorial to my iPhone device, I got a &#8220;Code Sign error: The identity &#8216;iPhone Developer: Romain Marucchi-Foino (VC824XU999)&#8217; doesn&#8217;t match any valid certificate/private key pair in the default keychain&#8221;.</p>
<p>To fix this so I could deploy, I clicked &#8220;Project &gt; Edit Project Settings&#8221;. I changed the Code Signing Identity to point to my cert.  I got the same error. I searched the file system to try and figure out where that string was coming from.  In Visual Studio, sometimes I have to edit the project file with a text editor to fix weird issues like that.  So, I opened up the *.xcodeproj file to see if I could find it there.  I use TextMate for my Ruby code so I fired it up to open that and it turns out that *.xcodeproj is not a file but a package or directory or whatever Mac fanboys call it.  Inside I found the project file and found the string.  I wanted to figure out how to fix this through the UI so I didn&#8217;t just change the text there.  I did notice though that the old cert was listed under a different profile.</p>
<p>So, back in the project properties, I selected &#8220;All Settings&#8221; in the configuration drop down and changed the cert once again to my cert and everything worked!</p>
<p>UPDATE: Well, It happened to me again but this time, changing the code signing cert didn&#8217;t help.  I had to go into the actual project file by right/command clicking on myproject.xcodeproj and selecting &#8220;Show Package Contents&#8221;.  Edit project.pbxproj with a text editor.  Search for: &#8220;CODE_SIGN_IDENTITY[sdk=iphoneos*]&#8221; = &#8220;iPhone Developer: Romain Marucchi-Foino (VC824XU999)&#8221;;  Replace all of these with your own identity.  for me it was: CODE_SIGN_IDENTITY = &#8220;iPhone Developer: Jason Rowland (2RK77WERHG)&#8221;;  Save the file, and go back to xcode.  It will prompt you to reload from disk and say yes.  Maybe another day I&#8217;ll figure out where the setting is in the GUI but now that I know I can change these things with a text editor, I probably never will <img src='http://www.jasonrowland.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.jasonrowland.com/2009/08/code-sign-error-the-identity-doesnt-match-any-valid-certificate/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Objective-C</title>
		<link>http://www.jasonrowland.com/2009/06/objective-c/</link>
		<comments>http://www.jasonrowland.com/2009/06/objective-c/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 07:19:17 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://www.jasonrowland.com/?p=30</guid>
		<description><![CDATA[Here are some interesting things I learned today about the differences between java/C# and Objective-C.  Also how to play a sound on your iPhone. Calling Methods This was the very first thing that jumped out at me when I started using Objective-C.  To call a method, you use the following syntax: [object message:param1 namedParam2:param2 namedParam3:param3]; [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some interesting things I learned today about the differences between java/C# and Objective-C.  Also how to play a sound on your iPhone.</p>
<p><strong>Calling Methods</strong></p>
<p>This was the very first thing that jumped out at me when I started using Objective-C.  To call a method, you use the following syntax:</p>
<pre>[object message:param1 namedParam2:param2 namedParam3:param3];</pre>
<p>You can call a property by using a more familiar dot notation though.</p>
<pre>[object setProperty:value];
object.property = value;</pre>
<p>Those two lines of code are equivalent.  Even though the brackets are awkward to me, I really love the fact that it has named parameters.  You always read in your code what the heck it is you are passing in.  I love this feature.  I wish java and C# both had this feature for the readability of the code alone.</p>
<p>[Update: 6/11]</p>
<p>Thanks to Martin for pointing out to me that these are not actually named parameters.  The order matters and the parameters help make up the function name.  I confirmed this for myself by writing the following two functions.</p>
<pre>
- (<span>void</span>) play:(<span>id</span>)x withDuration:(<span>id</span>)y withVolume:(<span>id</span>)z
{
<span>    // </span><span>
}</span>

- (<span>void</span>) play:(<span>id</span>)x withVolume:(<span>id</span>)z withDuration:(<span>id</span>)y
{
<span>    // </span><span>
} </span></pre>
<p>These are two different methods.  They have the names &#8220;play:withDuration:withVolume&#8221; and &#8220;play:withVolume:withDuration&#8221;</p>
<p><strong>Garbage Collection</strong></p>
<p>This one is interesting to me.  Objective-C supports garbage collection the same as C#.  The unfortunate thing is that it is only supported when developing for the Mac.  It is not supported on the iPhone.  When programming for the iPhone, you have to worry about memory management like you did back in the old days.  This means you have to concern yourself with error prone reference counting with methods &#8220;release&#8221;, &#8220;retain&#8221;.  This has been the cause of many bugs in the past and could cause your app to suddenly quit unexpectedly if you aren&#8217;t careful with memory leaks.  The confusion usually was around who was responsible for freeing an object.  Was it the library or the calling object?  Fortunately, Apple has a firm policy on when to free objects.  Basically, you free any object you create.  You“create”an object using a method whose name begins with “alloc” or “new” or contains “copy”.  If you own an object, you are responsible for calling &#8220;release&#8221; on the object.  Do NOT call release on an object you do not own or you will most likely cause very bad things to happen because the object will have been freed before it was supposed to.  If you just follow this convention in your own code, you should reduce your chance for this kind of bug.</p>
<p>There are some classes that have convienience methods that return new objects but are not considered created by the calling method.  They are not named with &#8220;alloc&#8221;, &#8220;new&#8221;, or &#8220;copy&#8221;.  One example is [NSString stringWithFormat].  This returns a newly created string, but it is created as an autoreleased object.  Since we don&#8217;t control when they are released, it&#8217;s good practice to avoid using them unless there&#8217;s a good reason.</p>
<p>I know this is going to trip me up since I&#8217;ve been using garbage collection in java and C# for for a LONG time.</p>
<p><strong>Class Methods and Instance Methods</strong></p>
<pre>- (id) foo {
    return foo;
}</pre>
<pre>
<pre>+ (id) foo {
    return foo;
}</pre>
</pre>
<p>The first thing this c# developer noticed was that little &#8220;-&#8221; minus sign at the start of the line.  In the java and c# worlds, we are used to putting private/protected/public in front of these methods.  I assumed that this was probably a private designator.  Wrong.  This minus sign actually identifies this method as a method that can be used on an instance object.  In both java and C#, you do not put anything in front of the method to identify it as an instance method.  The &#8220;+&#8221; plus sign designates a class method.  This is similar to &#8220;static&#8221; in java and C#.  When I thought about it a little more, it makes sense.  In Objective-C you have an interface file where you declare the public methods.</p>
<p><strong>Object Identifiers</strong></p>
<p>The second thing is (id).  id is a built in type in Objective-C.  It is the object identifier.  It is a pointer to a struct. All objects are of type id.  In a similar way every object in C# inherit from &#8220;Object&#8221;.</p>
<p>[Updated: 6/11]</p>
<p>id is more similar to the &#8220;var&#8221; keyword in C#.  It&#8217;s simply a way of using dynamic typing instead of static typing.  Thanks Martin.</p>
<p><strong>Properties</strong></p>
<p>You declare your property i the import file as follows:</p>
<pre>@property (retain, nonatomic) UILabel* foo;</pre>
<p>The retain here is required because the iPhone is not garbage collected.  It will give you a warning if you do not put it here.  The other attribute nonatomic tells the compiler that it doesn&#8217;t need to worry about creating thread safe code for the methods.</p>
<p>There are two different ways to implement the property.  We will discuss the verbose way first.  When creating a property called &#8220;foo&#8221;, you need to create two instance methods &#8220;foo&#8221; and &#8220;setFoo&#8221;.  This is more similar to the java way of handling properties except in java it is &#8220;getFoo&#8221;.</p>
<pre>
<pre>- (UILabel*) foo {
    return foo;
}
- (void) setFoo: (UILabel*) aFoo {
    if (aFoo != foo) {
        [aFoo retain];
        [foo release];
        foo = aFoo;
    }
}</pre>
</pre>
<p>The other way to implement the property is a shortcut where the compiler implements it for you.  It would only work for simple getters and setters but it saves typing when they are boring methods anyway.  You simply add the following to the top of your implementation file:</p>
<pre>@synthesize foo;</pre>
<p><strong>MVC</strong></p>
<p>It seems to me that the MVC architecture is used by default when writing an app for the iPhone.  You can write MVC in any platform, but what I&#8217;ve noticed is that most developers tend to program based on the first examples they read. One aspect that I haven&#8217;t quite figured out is the whole Interface Builder and the whole IBOutlet stuff.  IBOutlet is basically just a define, but Interface Builder uses these tags to know what is available to connect things.  You can drag connections and events using these tags.  I don&#8217;t think I fully understand what I&#8217;m doing when I&#8217;m making the connections.  I understand how to make things work, but I guess I don&#8217;t understand on an intuitive level yet.  Hopefully more experience will give that to me.</p>
<p><strong>Playing a sound</strong></p>
<p>Whenever this button was pressed, I wanted to play a sound.  Here is the code I used to do this:</p>
<pre>SystemSoundID soundId;
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *path = [mainBundle pathForResource:@"filename" ofType:@"wav"];
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &amp;soundId); 
AudioServicesPlaySystemSound(soundId);</pre>
<p>I have these in different classes but this is the correct sequence.  I created a SoundEffect class do do the actual audio work so I don&#8217;t have a reference to the audio includes in the main part of my program.  This should work, but if not, I followed this good tutorial: <a href="http://www.iphonedevcentral.org/tutorials.php?page=ViewTutorial&amp;id=50&amp;uid=57348970">http://www.iphonedevcentral.org/tutorials.php?page=ViewTutorial&amp;id=50&amp;uid=57348970</a>.  You will need to include the AudioToolbox in your Frameworks in order for this to work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jasonrowland.com/2009/06/objective-c/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

