<?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/"
	>

<channel>
	<title>[iPhone developer:tips];</title>
	<atom:link href="http://iPhoneDeveloperTips.com/feed" rel="self" type="application/rss+xml" />
	<link>http://iPhoneDeveloperTips.com</link>
	<description>Tips and Tricks for iPhone developers</description>
	<pubDate>Wed, 01 Jul 2009 03:03:12 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Silent Mode Switch and Playing Sounds</title>
		<link>http://iPhoneDeveloperTips.com/audio/silent-mode-switch-and-playing-sounds.html</link>
		<comments>http://iPhoneDeveloperTips.com/audio/silent-mode-switch-and-playing-sounds.html#comments</comments>
		<pubDate>Wed, 01 Jul 2009 02:50:53 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
		
		<category><![CDATA[Audio]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=2469</guid>
		<description><![CDATA[In a previous tip, Playing Short Sounds, I wrote an example to show how you can play a short sound, up to 30 seconds, by calling one of the C-based functions in the Audio Session Services library. 
There is one aspect of this that can be troublesome - by default, playing an Audio Session sound [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous tip, <a target="_blank" href="http://iphonedevelopertips.com/audio/playing-short-sounds-audio-session-services.html">Playing Short Sounds</a>, I wrote an example to show how you can play a short sound, up to 30 seconds, by calling one of the C-based functions in the Audio Session Services library. </p>
<p>There is one aspect of this that can be troublesome - by default, playing an Audio Session sound will ~not~ respect the setting of the mute switch on the iPhone. In other words, if you make a call to play a sound and the silent (hardware) switch on the iPhone is set to silent, you&#8217;ll still hear the sound.<br />
<span id="more-2469"></span>  </p>
<p>To respect the setting of the silent switch, add this code above any calls to play a sound:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Choose a category identifier for audio sessions</span>
UInt32 sessionCategory <span style="color: #002200;">=</span> kAudioSessionCategory_SoloAmbientSound;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Set the session property</span>
AudioSessionSetProperty<span style="color: #002200;">&#40;</span>kAudioSessionProperty_AudioCategory,
    <span style="color: #a61390;">sizeof</span><span style="color: #002200;">&#40;</span>sessionCategory<span style="color: #002200;">&#41;</span>, <span style="color: #002200;">&amp;</span>sessionCategory<span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>There are a number of pre-defined session categories, many will have the same end result as the kAudioSessionCategory_SoloAmbientSound that I opted to use.</p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/audio/silent-mode-switch-and-playing-sounds.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>iPhone SDK 3 and Deprecated Method Warnings</title>
		<link>http://iPhoneDeveloperTips.com/cocoa/iphone-sdk-3-and-deprecated-methods.html</link>
		<comments>http://iPhoneDeveloperTips.com/cocoa/iphone-sdk-3-and-deprecated-methods.html#comments</comments>
		<pubDate>Tue, 30 Jun 2009 01:55:50 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
		
		<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=2499</guid>
		<description><![CDATA[A side-effect of developing code on platforms that continue to evolve, is dealing with methods that become deprecated from one release to another. If you&#8217;ve spent anytime at all with Java, you are all too familiar with this concept. With the release of the iPhone SDK version 3.0, a number of methods have been become [...]]]></description>
			<content:encoded><![CDATA[<p>A side-effect of developing code on platforms that continue to evolve, is dealing with methods that become deprecated from one release to another. If you&#8217;ve spent anytime at all with Java, you are all too familiar with this concept. With the release of the iPhone SDK version 3.0, a number of methods have been become subject to the same fate. </p>
<p>Here is how I came about this in my most recent app. I have a subclass of <strong>UITableViewCell</strong> that looks as follows:<br />
<span id="more-2499"></span></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> WeaponCell <span style="color: #002200;">:</span> UITableViewCell 
<span style="color: #002200;">&#123;</span>
  UIImageView <span style="color: #002200;">*</span>image; 
  ...
<span style="color: #002200;">&#125;</span>
&nbsp;
...
&nbsp;
<span style="color: #11740a; font-style: italic;">// An instance of WeaponCell</span>
WeaponCell <span style="color: #002200;">*</span>cell;</pre></div></div>

<p>Prior to installing the 3.0 SDK, I would set the image as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">  cell.image <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;weapon.png&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>However, with 3.0, the <strong>image</strong> method for <strong>UITableViewCell</strong> now states this: &#8220;Deprecated. Instead use the <strong>imageView</strong> property to get <strong>UIImageView</strong> object and then get or set the encapsulated image.&#8221;</p>
<p>Trouble is, you can&#8217;t simply make the appropriate code change if there&#8217;s any chance you need to build for a device that is running 2.x (or earlier). For example, I had to create an adhoc release today for someone who is running a device that has not been upgraded, and rolling back the code to pre-3.0 was not on the agenda. Here&#8217;s a much better solution:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// That's two underscores before IPHONE</span>
<span style="color: #6e371a;">#if __IPHONE_3_0</span>
  cell.imageView.image <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;weapon.png&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #6e371a;">#else</span>
  cell.image <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;weapon.png&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #6e371a;">#endif</span></pre></div></div>

<p>Likewise, the font property of <strong>UIButton</strong> has been deprecated and you now are directed to use <strong>titleLabel</strong> property instead.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UIButton <span style="color: #002200;">*</span>backButton <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIButton alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>frame<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #6e371a;">#if __IPHONE_3_0</span>
  backButton.titleLabel.font <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIFont systemFontOfSize<span style="color: #002200;">:</span><span style="color: #2400d9;">15.0</span><span style="color: #002200;">&#93;</span>;
<span style="color: #6e371a;">#else</span>
  backButton.font <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIFont systemFontOfSize<span style="color: #002200;">:</span><span style="color: #2400d9;">15</span><span style="color: #002200;">&#93;</span>;
<span style="color: #6e371a;">#endif</span></pre></div></div>

<p>Deprecated methods, one of those things that you get to live with as a software developer. Good news is, there are reasonable work-arounds that make for managing this issue pretty painless.</p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/cocoa/iphone-sdk-3-and-deprecated-methods.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Snoop Dogg App on the iPhone - iFizzle</title>
		<link>http://iPhoneDeveloperTips.com/announcements/snoop-dogg-app-on-the-iphone.html</link>
		<comments>http://iPhoneDeveloperTips.com/announcements/snoop-dogg-app-on-the-iphone.html#comments</comments>
		<pubDate>Sat, 27 Jun 2009 14:17:48 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
		
		<category><![CDATA[Announcements]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=2451</guid>
		<description><![CDATA[I recently completed an iPhone application for Snoop Dogg. Check this out: Snoop did a demo of the application on the Tonight Show with Conan O&#8217;Brien.

If you interested to learn more about the app, or have an idea for something similar you would like developed, drop me a note. You can also  visit 3 [...]]]></description>
			<content:encoded><![CDATA[<p>I recently completed an iPhone application for Snoop Dogg. Check this out: Snoop did a demo of the application on the Tonight Show with Conan O&#8217;Brien.</p>
<p><object width="425" height="350" height="350" width="425" data="http://www.youtube.com/v/SfFRULbjuXQ" type="application/x-shockwave-flash"><param name="src" value="http://www.youtube.com/v/SfFRULbjuXQ" /></object></p>
<p>If you interested to learn more about the app, or have an idea for something similar you would like developed, <a title="Contact" href="http://iphonedevelopertips.com/contact" target="_blank" title="Contact">drop me a note</a>. You can also  visit <a target="_blank" href="http://3sixtysoftware.com/">3 Sixty Software</a>, the business end of my iPhone development.</p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/announcements/snoop-dogg-app-on-the-iphone.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Playing Short Sounds - Audio Session Services</title>
		<link>http://iPhoneDeveloperTips.com/audio/playing-short-sounds-audio-session-services.html</link>
		<comments>http://iPhoneDeveloperTips.com/audio/playing-short-sounds-audio-session-services.html#comments</comments>
		<pubDate>Sat, 27 Jun 2009 05:09:33 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
		
		<category><![CDATA[Audio]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=2424</guid>
		<description><![CDATA[If you need to play short sounds, less than 30 seconds, Audio Session Services are your friend. Here is a snippet of code to play a wav file:

SystemSoundID soundID;
NSString *path = &#91;&#91;NSBundle mainBundle&#93;
   pathForResource:@&#34;RapidFire&#34; ofType:@&#34;wav&#34;&#93;;    
&#160;
AudioServicesCreateSystemSoundID&#40;&#40;CFURLRef&#41;&#91;NSURL fileURLWithPath:path&#93;,&#38;soundID&#41;;
AudioServicesPlaySystemSound &#40;soundID&#41;;


For this to work, you will need to import &#60;AudioToolbox/AudioToolbox.h&#62; header file, and [...]]]></description>
			<content:encoded><![CDATA[<p>If you need to play short sounds, less than 30 seconds, Audio Session Services are your friend. Here is a snippet of code to play a wav file:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">SystemSoundID soundID;
<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;RapidFire&quot;</span> ofType<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;wav&quot;</span><span style="color: #002200;">&#93;</span>;    
&nbsp;
AudioServicesCreateSystemSoundID<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>CFURLRef<span style="color: #002200;">&#41;</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>,<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><span id="more-2424"></span></p>
<p>For this to work, you will need to import &lt;AudioToolbox/AudioToolbox.h&gt; header file, and also add the AudioToolbox.framework to your project.</p>
<p>For those interested in a little background information, Audio Session Services is a set of functions written in C. There are a few subtleties that give this away. Here is the definition for the AudioServicesCreateSystemSoundID function:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">OSStatus AudioServicesCreateSystemSoundID <span style="color: #002200;">&#40;</span>
   CFURLRef       inFileURL, 
   SystemSoundID  <span style="color: #002200;">*</span>outSystemSoundID<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>The giveaway is how we call this function:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">AudioServicesCreateSystemSoundID<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>CFURLRef<span style="color: #002200;">&#41;</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>,<span style="color: #002200;">&amp;</span>soundID<span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>Notice the parameter outSystemSoundID, which is a pointer to SystemSoundID, a 32 bit unsigned integer. To pass this value as a pointer in C, you pass the address of the variable, which is done using &#038;soundID.</p>
<p>More tips on Audio Session Services in the works&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/audio/playing-short-sounds-audio-session-services.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Xcode, Folders and the File System - Part 2</title>
		<link>http://iPhoneDeveloperTips.com/xcode/xcode-folders-and-the-file-system-part-2.html</link>
		<comments>http://iPhoneDeveloperTips.com/xcode/xcode-folders-and-the-file-system-part-2.html#comments</comments>
		<pubDate>Tue, 09 Jun 2009 13:54:21 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
		
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=2393</guid>
		<description><![CDATA[In Part 1 of Xcode, Folders and the File System I walked through a short example on how to import folders into Xcode such that resources within a project have a folder structure that matches the file system.
In this post I will show you two ways to access the imported resources, one by specifying a [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://iphonedevelopertips.com/xcode/xcode-folders-and-the-file-system-part-1.html">Part 1 of Xcode, Folders and the File System</a> I walked through a short example on how to import folders into Xcode such that resources within a project have a folder structure that matches the file system.</p>
<p>In this post I will show you two ways to access the imported resources, one by specifying a path, one using an application bundle, both examples will focus on working with images. The code below is an example of building a path to a resource, avoiding a hardcoded path by using index values maintained within the application.<br />
<span id="more-2393"></span></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">int</span> modelIndex <span style="color: #002200;">=</span> <span style="color: #2400d9;">2</span>, imageIndex <span style="color: #002200;">=</span> <span style="color: #2400d9;">5</span>;
...
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>imageName <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;/Model-%02d/coverflow/CoverFlow-%02d.jpg&quot;</span>, 
   modelIndex, imageIndex<span style="color: #002200;">&#93;</span>;
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;image: %@&quot;</span>, imageName<span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>The output in the debug console looks as follows, notice the full path to the image:</p>
<p>2009-06-09 08:20:30.732 AppName[25154:20b] image: /Model-02/coverflow/CoverFlow-05.jpg</p>
<p>You can create a <strong>UIImageView</strong> referencing the file using the code shown below. The method <strong>imageNamed:</strong> looks for the image in the application’s main bundle if this is the first request for the image. If the image has been loaded previously, the image is retrieved from the system maintained internal cache.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UIImageView <span style="color: #002200;">*</span>wallpaper <span style="color: #002200;">=</span> 
  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImageView alloc<span style="color: #002200;">&#93;</span> initWithImage<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span>imageName<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>There are times when you will need to reference resources by working with the main application bundle. Following on the same theme of working with images, caching of images is not always a good idea (see the post <a href="http://iphonedevelopertips.com/memory-management/images-and-caching.html">Images and Caching</a> for more information). In this case, using the method <strong>imageWithContentsOfFile:</strong> is a better option. However, there is one difference we need to account for when using this method, namely, <strong>imageWithContentsOfFile:</strong> loads image data from a specified path, however, it will not look in the application bundle by default.</p>
<p>Creating the proper path can be as simple as:</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;Splash&quot;</span> ofType<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;jpg&quot;</span> inDirectory<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&quot;</span><span style="color: #002200;">&#93;</span>; 
UIImageView <span style="color: #002200;">*</span>background <span style="color: #002200;">=</span> 
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImageView alloc<span style="color: #002200;">&#93;</span> initWithImage<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIImage imageWithContentsOfFile<span style="color: #002200;">:</span>path<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>In order for <strong>imageWithContentsOfFile:</strong> to work with images imported from the file system as I demonstrated in Part 1, we need to specify the full path to the resource, here&#8217;s how that code might look:</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>dir <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;Model-%02d/coverflow&quot;</span>, modelIndex<span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>file <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;CoverFlow-%02d&quot;</span>, imageIndex<span style="color: #002200;">&#93;</span>; 
<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>file
   ofType<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;jpg&quot;</span> inDirectory<span style="color: #002200;">:</span>dir<span style="color: #002200;">&#93;</span>;
UIImageView <span style="color: #002200;">*</span>wallpaper <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImageView alloc<span style="color: #002200;">&#93;</span> 
  initWithImage<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIImage imageWithContentsOfFile<span style="color: #002200;">:</span>path<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Working with files directly imported from the file system can be quite useful, even more so when there are many files to manage within an application. However, you will need to keep in mind how to access the resources, either through a full path or by working with an application bundle.</p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/xcode/xcode-folders-and-the-file-system-part-2.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Xcode, Folders and the File System - Part 1</title>
		<link>http://iPhoneDeveloperTips.com/xcode/xcode-folders-and-the-file-system-part-1.html</link>
		<comments>http://iPhoneDeveloperTips.com/xcode/xcode-folders-and-the-file-system-part-1.html#comments</comments>
		<pubDate>Mon, 08 Jun 2009 16:15:01 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
		
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=2362</guid>
		<description><![CDATA[Xcode provides a built in mechanism for organzing content within a project (control-click or right click -&#62; Add -&#62; New Group). For example, in the image below, I&#8217;ve created a number of groups for separating the primary functionality of an application into model classes and views. 

Although this is nice, for the most part the [...]]]></description>
			<content:encoded><![CDATA[<p>Xcode provides a built in mechanism for organzing content within a project (control-click or right click -&gt; Add -&gt; New Group). For example, in the image below, I&#8217;ve created a number of groups for separating the primary functionality of an application into model classes and views. </p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2009/06/xcode-groups.png" /></p>
<p>Although this is nice, for the most part the file structure as stored on the system is still flat. In other words, Xcode manages this information internally, it does not create corresponding folders on the file system.<br />
<span id="more-2362"></span></p>
<p>In a recent application I was working with large sets of images. The question was, how to best manage all the images within Xcode such that I could leverage the inherent nature of folders and sub-folders on the file system. Let me explain a little further.</p>
<p><img style="max-width: 800px;" src="http://iPhoneDeveloperTips.com/wp-content/uploads/2009/06/filesys.png" /></p>
<p>From the figure above you can get an idea of how I chose to break down the content. There was a total of 12 models, for each model there were  up to 40 images in the folder <strong>/coverflow</strong> (see the image on the right), a separate folder for wallpaper images, with an image that corresponds to each coverflow image, as well as a handful of other images such a headshot, MenuButton, etc.</p>
<p>On the file system this is a logical breakdown of content, and if I were to use this same structure within the application I could build a path to the appropriate folder in the resource bundle using an index value to specify which folder I am after (/Model-01, /Model-02, etc). This would allow for code that can access the same files, regardless of which model the user selected, no hard-coding of file names and paths.</p>
<p>There were two tricks to get this to work within Xcode. The first trick is to properly import the file contents into Xcode. Here&#8217;s how you do that:</p>
<p><strong>Step #1: </strong>In the project, right click (control-click) and choose Add -&gt; Existing Files:</p>
<p><img style="max-width: 800px;" src="http://iPhoneDeveloperTips.com/wp-content/uploads/2009/06/add1.png" /></p>
<p><strong>Step #2: </strong>Choose the folders on the file system to import:</p>
<p><img style="max-width: 800px;" src="http://iPhoneDeveloperTips.com/wp-content/uploads/2009/06/add2.png" /></p>
<p><strong>Step #3: </strong>After clicking on Add, you will be prompted with the dialog box below. Chose to copy the files into the project as well as create the folder references in the project:</p>
<p>&nbsp;<img style="max-width: 800px;" src="http://iPhoneDeveloperTips.com/wp-content/uploads/2009/06/add3.png" /></p>
<p>You&#8217;ll know that all is well if the folder references appear as blue folders (shown below).</p>
<p><img style="max-width: 800px;" src="http://iPhoneDeveloperTips.com/wp-content/uploads/2009/06/add4.png" /></p>
<p>The second trick was to properly reference resources within the application. This was straightforward for images that I wanted the system to cache, however it required a few extra steps for those images I didn&#8217;t want cached. More on this, and the code to make it all work, in Part II.</p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/xcode/xcode-folders-and-the-file-system-part-1.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>UIColor Macros</title>
		<link>http://iPhoneDeveloperTips.com/cocoa/uicolor-macros.html</link>
		<comments>http://iPhoneDeveloperTips.com/cocoa/uicolor-macros.html#comments</comments>
		<pubDate>Fri, 05 Jun 2009 12:23:16 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
		
		<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=2342</guid>
		<description><![CDATA[Below are two macros I paste inside every new iPhone project. Besides saving a few keystrokes, they work well when using the color picker application. Let&#8217;s look at the macros first:

 #define RGB(r, g, b) 
    &#91;UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1&#93;
 #define RGBA(r, g, b, a) 
    &#91;UIColor colorWithRed:r/255.0 [...]]]></description>
			<content:encoded><![CDATA[<p>Below are two macros I paste inside every new iPhone project. Besides saving a few keystrokes, they work well when using the color picker application. Let&#8217;s look at the macros first:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"> <span style="color: #6e371a;">#define RGB(r, g, b) </span>
    <span style="color: #002200;">&#91;</span>UIColor colorWithRed<span style="color: #002200;">:</span>r<span style="color: #002200;">/</span><span style="color: #2400d9;">255.0</span> green<span style="color: #002200;">:</span>g<span style="color: #002200;">/</span><span style="color: #2400d9;">255.0</span> blue<span style="color: #002200;">:</span>b<span style="color: #002200;">/</span><span style="color: #2400d9;">255.0</span> alpha<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>
 <span style="color: #6e371a;">#define RGBA(r, g, b, a) </span>
    <span style="color: #002200;">&#91;</span>UIColor colorWithRed<span style="color: #002200;">:</span>r<span style="color: #002200;">/</span><span style="color: #2400d9;">255.0</span> green<span style="color: #002200;">:</span>g<span style="color: #002200;">/</span><span style="color: #2400d9;">255.0</span> blue<span style="color: #002200;">:</span>b<span style="color: #002200;">/</span><span style="color: #2400d9;">255.0</span> alpha<span style="color: #002200;">:</span>a<span style="color: #002200;">&#93;</span></pre></div></div>

<p>Here&#8217;s the code without/with the macro:<br />
<span id="more-2342"></span></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"> <span style="color: #11740a; font-style: italic;">// Code without the macro</span>
  msgLabel.textColor <span style="color: #002200;">=</span> 
     <span style="color: #002200;">&#91;</span>UIColor colorWithRed<span style="color: #002200;">:</span><span style="color: #2400d9;">255</span><span style="color: #002200;">/</span><span style="color: #2400d9;">255.0</span> green<span style="color: #002200;">:</span><span style="color: #2400d9;">251</span><span style="color: #002200;">/</span><span style="color: #2400d9;">255.0</span> blue<span style="color: #002200;">:</span><span style="color: #2400d9;">204</span><span style="color: #002200;">/</span><span style="color: #2400d9;">255.0</span> alpha<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Or like this...</span>
  msgLabel.textColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor colorWithRed<span style="color: #002200;">:</span><span style="color: #2400d9;">1.0</span> green<span style="color: #002200;">:</span>.98 blue<span style="color: #002200;">:</span>.8 alpha<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
&nbsp;
 <span style="color: #11740a; font-style: italic;">// Code with macro</span>
  msgLabel.textColor <span style="color: #002200;">=</span> RGB<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">255</span>, <span style="color: #2400d9;">251</span>, <span style="color: #2400d9;">204</span><span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>UIColor expects its parameters to be expressed as values in the range of 0.0 to 1.0, so I pass in the color value I&#8217;m looking for between 0 and 255, and let the macro do the math for me.</p>
<p>Let me show you how I use the macro with the color picker application. The figure below shows a screenshot of the color picker - at this point I have selected the color I am interested in, so I choose rgb from the dropdown menu.</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2009/06/color2.png" /></p>
<p>From here, I copy the value from the field <strong>&#8220;Hex:&#8221;</strong>, paste this into my project and finish by changing <strong>rgb</strong> to <strong>RGB</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/cocoa/uicolor-macros.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Finding the Xcode Project File in a Folder</title>
		<link>http://iPhoneDeveloperTips.com/xcode/finding-the-xcode-project-file-in-a-folder.html</link>
		<comments>http://iPhoneDeveloperTips.com/xcode/finding-the-xcode-project-file-in-a-folder.html#comments</comments>
		<pubDate>Mon, 01 Jun 2009 22:54:46 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
		
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=2338</guid>
		<description><![CDATA[This barely qualifies as a tip worthy of publishing, however, it&#8217;s something I use regularly so I figured it&#8217;s worthwhile passing on.
I&#8217;ve been working with some monster projects as it relates to content. What that translates to is really long lists of files inside of Finder. Since I bounce between a handful of projects over [...]]]></description>
			<content:encoded><![CDATA[<p>This barely qualifies as a tip worthy of publishing, however, it&#8217;s something I use regularly so I figured it&#8217;s worthwhile passing on.</p>
<p>I&#8217;ve been working with some monster projects as it relates to content. What that translates to is really long lists of files inside of Finder. Since I bounce between a handful of projects over the course of the week, more often than not I opt to open a project from by browsing the files within Finder and opening the file with the extension .xcodeproj. With folders having many files, I quickly tired of scrolling down the file list looking for the xcode project file. </p>
<p>To bubble the project file to the top, I simply rename the project file and place an underscore at the front of the project name. For example, <strong>SomeProject.xcodeproj</strong> becomes <strong>_SomeProject.xcodeproj</strong>. This has no effect on the project (from Xcode&#8217;s perspective), however you may need to update your source code control system with the new (renamed) file.</p>
<p>Trivial as it is, a hand tip none-the-less.</p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/xcode/finding-the-xcode-project-file-in-a-folder.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Images and Caching</title>
		<link>http://iPhoneDeveloperTips.com/memory-management/images-and-caching.html</link>
		<comments>http://iPhoneDeveloperTips.com/memory-management/images-and-caching.html#comments</comments>
		<pubDate>Fri, 29 May 2009 01:54:50 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
		
		<category><![CDATA[Memory Management]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=2310</guid>
		<description><![CDATA[If you are working with a large number of images in an iPhone application, read on, chances are I can save you some trouble when it comes to memory management. Let me provide some background information&#8230;
I&#8217;ve been working on an application which has images divided into several sub-directories:

/imageSet01/thumbnails/pic01.png
/imageSet01/thumbnails/pic02.png
&#8230;
/imageSet10/thumbnails/pic01.png
/imageSet10/thumbnails/pic02.png
In addition, for each set of thumnails there [...]]]></description>
			<content:encoded><![CDATA[<p>If you are working with a large number of images in an iPhone application, read on, chances are I can save you some trouble when it comes to memory management. Let me provide some background information&#8230;</p>
<p>I&#8217;ve been working on an application which has images divided into several sub-directories:<br />
<span id="more-2310"></span></p>
<p>/imageSet01/thumbnails/pic01.png<br />
/imageSet01/thumbnails/pic02.png<br />
&#8230;<br />
/imageSet10/thumbnails/pic01.png<br />
/imageSet10/thumbnails/pic02.png</p>
<p>In addition, for each set of thumnails there is also an image that is viewable fullscreen, this image can also be saved to the camera roll if the user opts to do so.</p>
<p>/imageSet10/wallpaper/pic01.png<br />
/imageSet10/wallpaper/pic02.png<br />
&#8230;<br />
/imageSet10/wallpaper/pic01.png<br />
/imageSet10/wallpaper/pic02.png</p>
<p>All told, there are more 12 images sets, with up to 70 images per set. In addition, I&#8217;ve integrated a coverflow viewer that allows users to view a series of thumnails images by swiping left/right. To give you an idea of the space allocated for the coverflow, each image has a texture allocated that consumes 256K. With 70 images, I&#8217;m pushing 17MB. That does not include allocating each UIImage resource (from a file) to be shown on the texture.</p>
<p>With all that going for me, when it came to loading images for backgrounds, creating views, data structures, etc, you can see why it was important to keep a tight reign on allocation/releasing of objects.</p>
<p>One concept that wasn&#8217;t apparent up front, and the primary reason for this post, is that your choice of how you allocate UIImage can make a significant impact on your memory usage. What follows is a typical line of code, found in many examples and applications, for allocating images:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UIImageView <span style="color: #002200;">*</span>wallpaper <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImageView alloc<span style="color: #002200;">&#93;</span> 
  initWithImage<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;/imageSet02/wallpaper/pic02.png&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>The good news is, the iPhone will cache this image, so if you make this same request again, the image will be loaded from an internal cache versus loading from a resource. Bad news is, the iPhone will cache this image. In my application, this subtle caching of images for the coverflow as well as the fullscreen image preview, led to a significant problem, ultimately causing the application to crash.</p>
<p>Here&#8217;s another means to allocate an image and avoid the system caching:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UIImageView <span style="color: #002200;">*</span>wallpaper <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImageView alloc<span style="color: #002200;">&#93;</span>
  initWithImage<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIImage imageWithContentsOfFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;/imageSet02/wallpaper/pic02.png&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>So, with that long intro it really comes down to choosing between <em><strong>imageWithContentsOfFile</strong></em> and <em><strong>imageNamed</strong></em>, depending on your whether or not you prefer to have images cached. Now mind you, all of this is documented in the API, which is the segue to the second reason for this post - read the documentation closely! Finally, if you find a code example that looks to fit the bill for your application, again, consult the docs before simply copying/pasting. </p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/memory-management/images-and-caching.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Debugging Macros</title>
		<link>http://iPhoneDeveloperTips.com/debugging/debugging-macros.html</link>
		<comments>http://iPhoneDeveloperTips.com/debugging/debugging-macros.html#comments</comments>
		<pubDate>Tue, 26 May 2009 12:57:36 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
		
		<category><![CDATA[Debugging]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=2293</guid>
		<description><![CDATA[In a previous post, Yet Another Debug Output Replacement, I wrote a macro that I prefer over NSLog as the output does not prepend the date/time and object information that NSLog does.
Since that time I&#8217;ve pulled together a few more macros that I use on a regular basis for printing debug information on rectangles, points [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous post, <a href="http://iphonedevelopertips.com/debugging/yet-another-debug-output-nslog-replacement.html">Yet Another Debug Output Replacement</a>, I wrote a macro that I prefer over NSLog as the output does not prepend the date/time and object information that NSLog does.</p>
<p>Since that time I&#8217;ve pulled together a few more macros that I use on a regular basis for printing debug information on rectangles, points and sizes. I&#8217;ve also included a means to turn debug information on/off so debug statements are not included in builds targeted as final releases.<br />
<span id="more-2293"></span></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  </span>
<span style="color: #11740a; font-style: italic;">// Debug</span>
<span style="color: #11740a; font-style: italic;">//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span>
<span style="color: #6e371a;">#define DEBUG_ON  // Toggle to DEBUG_OFF to hide all debug code </span>
&nbsp;
<span style="color: #6e371a;">#ifdef DEBUG_ON</span>
  <span style="color: #6e371a;">#define debug(format, ...) CFShow([NSString stringWithFormat:format, ## __VA_ARGS__]);</span>
<span style="color: #6e371a;">#else</span>
  <span style="color: #6e371a;">#define debug(format, ...) </span>
<span style="color: #6e371a;">#endif</span>
&nbsp;
<span style="color: #6e371a;">#define debugRect(rect) debug(@&quot;%s x:%.4f, y:%.4f, w:%.4f, h%.4f&quot;, #rect,</span>
    rect.origin.x, rect.origin.y, rect.size.width, rect.size.height<span style="color: #002200;">&#41;</span>
<span style="color: #6e371a;">#define debugSize(size) debug(@&quot;%s w:%.4f, h:%.4f&quot;, #size, size.width, size.height)</span>
<span style="color: #6e371a;">#define debugPoint(point) debug(@&quot;%s x:%.4f, y:%.4f&quot;, #pt, pt.x, pt.y)</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/debugging/debugging-macros.html/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
