<?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>Webd &#187; Developpement</title>
	<atom:link href="http://webd.fr/tag/developpement/feed" rel="self" type="application/rss+xml" />
	<link>http://webd.fr</link>
	<description>Le blog de Julien Quéré</description>
	<lastBuildDate>Tue, 22 Mar 2011 15:49:19 +0000</lastBuildDate>
	<language>fr</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Nib2objc: Ou comment convertir un nib en code Objectif-C</title>
		<link>http://webd.fr/735-nib2objc-ou-comment-convertir-un-nib-en-code-objectif-c</link>
		<comments>http://webd.fr/735-nib2objc-ou-comment-convertir-un-nib-en-code-objectif-c#comments</comments>
		<pubDate>Wed, 10 Jun 2009 14:49:40 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Pro]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=735</guid>
		<description><![CDATA[L&#8217;utilisation d&#8217;Interface Builder s&#8217;avère très pratique pour les développeurs Cocoa Touch. C&#8217;est vrais que c&#8217;est génial de pouvoir créer ses interfaces en mode WYSIWYG. Oui mais voilà, cela peut poser quelques problèmes. Outre les cas où l&#8217;utilisation du code est &#8230; <a href="http://webd.fr/735-nib2objc-ou-comment-convertir-un-nib-en-code-objectif-c">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>L&#8217;utilisation d&#8217;Interface Builder s&#8217;avère très pratique pour les développeurs Cocoa Touch. C&#8217;est vrais que c&#8217;est génial de pouvoir créer ses interfaces en mode WYSIWYG. Oui mais voilà, cela peut poser quelques problèmes. Outre les cas où l&#8217;utilisation du code est nécessaire (pour atteindre la granularité voulue), on peut vouloir renoncer à l&#8217;utilisation des nibs pour des raisons de performance. </p>
<p>En effet, dans certains cas l&#8217;utilisation des nibs pose de sérieux problèmes de performance. On se retrouve ainsi avec un dur choix: soit on choisit la simplicité (et on utilise Interface Builder), soit on écrit ses interfaces directement dans le code et on gagne en performance. Dans certains cas, l&#8217;impact de l&#8217;utilisation des nibs sur la performance est quasi nul. La question ne se pose donc pas. Mais parfois, ce n&#8217;est pas le cas.<br />
<span id="more-735"></span><br />
Dans ce dernier cas de figure, il existe maintenant une solution: nib2objc. Ce projet Open-Source  est tout simplement un convertisseur de fichiers nib (.xib) vers du code Objectif-C. Il gère toutes les propriétés publiques de chacun des éléments graphiques, le constructeur et la hiérarchie des vues. Pour le moment, il n&#8217;y a que les composants d&#8217;UIKit qui sont supportés. L&#8217;utilisation est on-ne-peut-plus simple:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p735code3'); return false;">View Code</a> TEXT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7353"><td class="code" id="p735code3"><pre class="text" style="font-family:monospace;">imac-de-julien-2:Debug julien$ ./nib2objc demo.xib &gt; demo.m</pre></td></tr></table></div>

<p><a href="http://webd.fr/wp-content/uploads/2009/06/image-6.png" rel="lightbox[735]" title="image-6"><img src="http://webd.fr/wp-content/uploads/2009/06/image-6-300x224.png" alt="image-6" title="image-6" width="300" height="224" class="aligncenter size-medium wp-image-738" /></a></p>
<p>Et voilà le résultat pour ce nib:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p735code4'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7354"><td class="code" id="p735code4"><pre class="objc" style="font-family:monospace;">UILabel <span style="color: #002200;">*</span>view6 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UILabel alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">20.0</span>, <span style="color: #2400d9;">20.0</span>, <span style="color: #2400d9;">260.0</span>, <span style="color: #2400d9;">21.0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
view6.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">20.0</span>, <span style="color: #2400d9;">20.0</span>, <span style="color: #2400d9;">260.0</span>, <span style="color: #2400d9;">21.0</span><span style="color: #002200;">&#41;</span>;
view6.adjustsFontSizeToFitWidth <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
view6.alpha <span style="color: #002200;">=</span> <span style="color: #2400d9;">1.000</span>;
view6.autoresizingMask <span style="color: #002200;">=</span> UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
view6.baselineAdjustment <span style="color: #002200;">=</span> UIBaselineAdjustmentAlignCenters;
view6.clearsContextBeforeDrawing <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
view6.clipsToBounds <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
view6.contentMode <span style="color: #002200;">=</span> UIViewContentModeScaleToFill;
view6.enabled <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
view6.font <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIFont fontWithName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Helvetica&quot;</span> size<span style="color: #002200;">:</span><span style="color: #2400d9;">17.000</span><span style="color: #002200;">&#93;</span>;
view6.hidden <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view6.lineBreakMode <span style="color: #002200;">=</span> UILineBreakModeTailTruncation;
view6.minimumFontSize <span style="color: #002200;">=</span> <span style="color: #2400d9;">10.000</span>;
view6.multipleTouchEnabled <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view6.numberOfLines <span style="color: #002200;">=</span> <span style="color: #2400d9;">1</span>;
view6.opaque <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view6.shadowOffset <span style="color: #002200;">=</span> CGSizeMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.0</span>, <span style="color: #002200;">-</span><span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#41;</span>;
view6.tag <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
view6.text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Ma célule personalisée&quot;</span>;
view6.textAlignment <span style="color: #002200;">=</span> UITextAlignmentCenter;
view6.textColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor colorWithRed<span style="color: #002200;">:</span><span style="color: #2400d9;">0.000</span> green<span style="color: #002200;">:</span><span style="color: #2400d9;">0.000</span> blue<span style="color: #002200;">:</span><span style="color: #2400d9;">0.000</span> alpha<span style="color: #002200;">:</span><span style="color: #2400d9;">1.000</span><span style="color: #002200;">&#93;</span>;
view6.userInteractionEnabled <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
&nbsp;
UITableViewCell <span style="color: #002200;">*</span>view4 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UITableViewCell alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">300.0</span>, <span style="color: #2400d9;">182.0</span><span style="color: #002200;">&#41;</span> reuseIdentifier<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>null<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
view4.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">300.0</span>, <span style="color: #2400d9;">182.0</span><span style="color: #002200;">&#41;</span>;
view4.accessoryType <span style="color: #002200;">=</span> UITableViewCellAccessoryNone;
view4.alpha <span style="color: #002200;">=</span> <span style="color: #2400d9;">1.000</span>;
view4.autoresizingMask <span style="color: #002200;">=</span> UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
view4.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor colorWithRed<span style="color: #002200;">:</span><span style="color: #2400d9;">1.000</span> green<span style="color: #002200;">:</span><span style="color: #2400d9;">1.000</span> blue<span style="color: #002200;">:</span><span style="color: #2400d9;">1.000</span> alpha<span style="color: #002200;">:</span><span style="color: #2400d9;">1.000</span><span style="color: #002200;">&#93;</span>;
view4.clearsContextBeforeDrawing <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view4.clipsToBounds <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view4.contentMode <span style="color: #002200;">=</span> UIViewContentModeScaleToFill;
view4.font <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIFont fontWithName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Helvetica&quot;</span> size<span style="color: #002200;">:</span><span style="color: #2400d9;">17.000</span><span style="color: #002200;">&#93;</span>;
view4.hidden <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view4.hidesAccessoryWhenEditing <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
view4.indentationLevel <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
view4.indentationWidth <span style="color: #002200;">=</span> <span style="color: #2400d9;">10.000</span>;
view4.lineBreakMode <span style="color: #002200;">=</span> UILineBreakModeTailTruncation;
view4.multipleTouchEnabled <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view4.opaque <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
view4.selectedTextColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor colorWithWhite<span style="color: #002200;">:</span><span style="color: #2400d9;">1.000</span> alpha<span style="color: #002200;">:</span><span style="color: #2400d9;">1.000</span><span style="color: #002200;">&#93;</span>;
view4.selectionStyle <span style="color: #002200;">=</span> UITableViewCellSelectionStyleBlue;
view4.showsReorderControl <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view4.tag <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
view4.textAlignment <span style="color: #002200;">=</span> UITextAlignmentLeft;
view4.textColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor colorWithWhite<span style="color: #002200;">:</span><span style="color: #2400d9;">0.000</span> alpha<span style="color: #002200;">:</span><span style="color: #2400d9;">1.000</span><span style="color: #002200;">&#93;</span>;
view4.userInteractionEnabled <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
&nbsp;
UIButton <span style="color: #002200;">*</span>view7 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIButton buttonWithType<span style="color: #002200;">:</span>UIButtonTypeRoundedRect<span style="color: #002200;">&#93;</span>;
view7.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">101.0</span>, <span style="color: #2400d9;">49.0</span>, <span style="color: #2400d9;">99.0</span>, <span style="color: #2400d9;">37.0</span><span style="color: #002200;">&#41;</span>;
view7.adjustsImageWhenDisabled <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
view7.adjustsImageWhenHighlighted <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
view7.alpha <span style="color: #002200;">=</span> <span style="color: #2400d9;">1.000</span>;
view7.autoresizingMask <span style="color: #002200;">=</span> UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
view7.clearsContextBeforeDrawing <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view7.clipsToBounds <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view7.contentHorizontalAlignment <span style="color: #002200;">=</span> UIControlContentHorizontalAlignmentCenter;
view7.contentMode <span style="color: #002200;">=</span> UIViewContentModeScaleToFill;
view7.contentVerticalAlignment <span style="color: #002200;">=</span> UIControlContentVerticalAlignmentCenter;
view7.enabled <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
view7.font <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIFont fontWithName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Helvetica-Bold&quot;</span> size<span style="color: #002200;">:</span><span style="color: #2400d9;">15.000</span><span style="color: #002200;">&#93;</span>;
view7.hidden <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view7.highlighted <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view7.multipleTouchEnabled <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view7.opaque <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view7.reversesTitleShadowWhenHighlighted <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view7.selected <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view7.showsTouchWhenHighlighted <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view7.tag <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
view7.titleShadowOffset <span style="color: #002200;">=</span> CGSizeMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#41;</span>;
view7.userInteractionEnabled <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
<span style="color: #002200;">&#91;</span>view7 setTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Un bouton&quot;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>view7 setTitleColor<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIColor colorWithWhite<span style="color: #002200;">:</span><span style="color: #2400d9;">1.000</span> alpha<span style="color: #002200;">:</span><span style="color: #2400d9;">1.000</span><span style="color: #002200;">&#93;</span> forState<span style="color: #002200;">:</span>UIControlStateHighlighted<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>view7 setTitleColor<span style="color: #002200;">:</span>NSPatternColorSpace <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSImage_Class/"><span style="color: #400080;">NSImage</span></a> 0x2c3e5a0 Size<span style="color: #002200;">=</span><span style="color: #002200;">&#123;</span><span style="color: #2400d9;">320</span>, <span style="color: #2400d9;">460</span><span style="color: #002200;">&#125;</span> Reps<span style="color: #002200;">=</span><span style="color: #002200;">&#40;</span>
    <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSBitmapImageRep_Class/"><span style="color: #400080;">NSBitmapImageRep</span></a> 0x2c49460 Size<span style="color: #002200;">=</span><span style="color: #002200;">&#123;</span><span style="color: #2400d9;">320</span>, <span style="color: #2400d9;">460</span><span style="color: #002200;">&#125;</span> ColorSpace<span style="color: #002200;">=</span>NSDeviceRGBColorSpace BPS<span style="color: #002200;">=</span><span style="color: #2400d9;">8</span> BPP<span style="color: #002200;">=</span><span style="color: #2400d9;">32</span> Pixels<span style="color: #002200;">=</span>320x460 Alpha<span style="color: #002200;">=</span><span style="color: #a61390;">YES</span> Planar<span style="color: #002200;">=</span><span style="color: #a61390;">NO</span> Format<span style="color: #002200;">=</span><span style="color: #2400d9;">1</span>
<span style="color: #002200;">&#41;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>view7 setTitleShadowColor<span style="color: #002200;">:</span>NSNamedColorSpace System controlColor forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
&nbsp;
UISwitch <span style="color: #002200;">*</span>view8 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UISwitch alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">103.0</span>, <span style="color: #2400d9;">103.0</span>, <span style="color: #2400d9;">94.0</span>, <span style="color: #2400d9;">27.0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
view8.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">103.0</span>, <span style="color: #2400d9;">103.0</span>, <span style="color: #2400d9;">94.0</span>, <span style="color: #2400d9;">27.0</span><span style="color: #002200;">&#41;</span>;
view8.alpha <span style="color: #002200;">=</span> <span style="color: #2400d9;">1.000</span>;
view8.autoresizingMask <span style="color: #002200;">=</span> UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
view8.clearsContextBeforeDrawing <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
view8.clipsToBounds <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
view8.contentHorizontalAlignment <span style="color: #002200;">=</span> UIControlContentHorizontalAlignmentCenter;
view8.contentMode <span style="color: #002200;">=</span> UIViewContentModeScaleToFill;
view8.contentVerticalAlignment <span style="color: #002200;">=</span> UIControlContentVerticalAlignmentCenter;
view8.enabled <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
view8.hidden <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view8.highlighted <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
view8.multipleTouchEnabled <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
view8.on <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
view8.opaque <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view8.selected <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
view8.tag <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
view8.userInteractionEnabled <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
&nbsp;
<span style="color: #002200;">&#91;</span>view4 addSubview<span style="color: #002200;">:</span>view6<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>view4 addSubview<span style="color: #002200;">:</span>view7<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>view4 addSubview<span style="color: #002200;">:</span>view8<span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p>Comme vous pouvez le voir, c&#8217;est très verbeux. C&#8217;est parce que l&#8217;outil ne détecte pas les valeurs qui sont là par défaut. Donc dans le doute, il génère toutes les propriétés. A noter aussi que les valeurs des propriétés <code>UIImage</code>, <code>NSLocale</code> et <code>NSTimeZone</code> ne sont pas sorties dans le code. En effet, ibtool (sur lequel nib2objc se base) ne les supporte pas. </p>
<p><a href="http://kosmaczewski.net/projects/nib2objc/">Plus d&#8217;informations sur la page du projet nib2objc du site d&#8217;Adrian Kosmaczewski</a>. <!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/735-nib2objc-ou-comment-convertir-un-nib-en-code-objectif-c/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Comparer deux NSDate</title>
		<link>http://webd.fr/637-comparer-deux-nsdate</link>
		<comments>http://webd.fr/637-comparer-deux-nsdate#comments</comments>
		<pubDate>Fri, 05 Jun 2009 08:49:47 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Pro]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=637</guid>
		<description><![CDATA[Il est souvent utile de comparer deux NSDate dans le temps. Il s&#8217;agit de savoir si une date est antérieure ou postérieure à une autre. Le mécanisme offert par Apple pour les comparaisons de NSDate n&#8217;est pas des plus pratiques. &#8230; <a href="http://webd.fr/637-comparer-deux-nsdate">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Il est souvent utile de comparer deux <code>NSDate</code> dans le temps. Il s&#8217;agit de savoir si une date est antérieure ou postérieure à une autre. Le mécanisme offert par Apple pour les comparaisons de <code>NSDate</code> n&#8217;est pas des plus pratiques. Il faut utiliser la méthode <code>compare:(NSDate*)date</code> qui retourne un objet de type <code>NSComparisonResult</code>. </p>
<p>Cette méthode est une méthode standard de Foundation. Elle permet, grâce à des résultats de comparaison standardisés d&#8217;effectuer un tri sur des objets de façon générique. Oui, mais Apple ne prévoit pas de méthodes un peu plus <i>haut niveau</i> pour les simples comparaisons de dates. Voilà pourquoi j&#8217;ai écrit rapidement une addition de la classe <code>NSDate</code> permettant de comparer deux dates intuitivement. Les voici:<br />
<span id="more-637"></span></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p637code7'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6377"><td class="code" id="p637code7"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  NSDateAdditions.h</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Julien on 28/05/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 Julien Quéré - Webd.fr. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &lt;Foundation/Foundation.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/"><span style="color: #400080;">NSDate</span></a> <span style="color: #002200;">&#40;</span>NSDateAdditions<span style="color: #002200;">&#41;</span> 
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> isLaterThanOrEqualTo<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/"><span style="color: #400080;">NSDate</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>date;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> isEarlierThanOrEqualTo<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/"><span style="color: #400080;">NSDate</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>date;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> isLaterThan<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/"><span style="color: #400080;">NSDate</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>date;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> isEarlierThan<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/"><span style="color: #400080;">NSDate</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>date;
<span style="color: #a61390;">@end</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #11740a; font-style: italic;">//  NSDateAdditions.m</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Julien on 28/05/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 Julien Quéré - Webd.fr. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;NSDateAdditions.h&quot;</span>
&nbsp;
&nbsp;
<span style="color: #a61390;">@implementation</span> <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/"><span style="color: #400080;">NSDate</span></a> <span style="color: #002200;">&#40;</span>NSDateAdditions<span style="color: #002200;">&#41;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> isLaterThanOrEqualTo<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/"><span style="color: #400080;">NSDate</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>date <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #002200;">!</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>self compare<span style="color: #002200;">:</span>date<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> NSOrderedAscending<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> isEarlierThanOrEqualTo<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/"><span style="color: #400080;">NSDate</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>date <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #002200;">!</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>self compare<span style="color: #002200;">:</span>date<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> NSOrderedDescending<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> isLaterThan<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/"><span style="color: #400080;">NSDate</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>date <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>self compare<span style="color: #002200;">:</span>date<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> NSOrderedDescending<span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> isEarlierThan<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/"><span style="color: #400080;">NSDate</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>date <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>self compare<span style="color: #002200;">:</span>date<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> NSOrderedAscending<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>

<p>L&#8217;utilisation, quant à elle est on-ne-peut plus simple:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p637code8'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6378"><td class="code" id="p637code8"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Compare a NSDate (maDate) and the actual date</span>
<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>maDate isEarlierThanOrEqualTo<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/"><span style="color: #400080;">NSDate</span></a> date<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;It's earlier or equal&quot;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">else</span>
<span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;It's later&quot;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p><!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/637-comparer-deux-nsdate/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Astuces développement iPhone 8: Modifier le __MyCompanyName__</title>
		<link>http://webd.fr/707-developpement-iphone-modifier-le-__mycompanyname__</link>
		<comments>http://webd.fr/707-developpement-iphone-modifier-le-__mycompanyname__#comments</comments>
		<pubDate>Tue, 02 Jun 2009 08:12:37 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Astuce]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=707</guid>
		<description><![CDATA[Je vois assez souvent, dans les fichiers de code qui passent entre mes mains, des en-têtes comme ceci: ?View Code OBJC// Created by Julien on 17/01/09. // Copyright 2009 __MyCompanyName__. All rights reserved. Le problème porte sur __MyCompanyName__. Il serait &#8230; <a href="http://webd.fr/707-developpement-iphone-modifier-le-__mycompanyname__">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Je vois assez souvent, dans les fichiers de code qui passent entre mes mains, des en-têtes comme ceci:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p707code11'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p70711"><td class="code" id="p707code11"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//  Created by Julien on 17/01/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 __MyCompanyName__. All rights reserved.</span></pre></td></tr></table></div>

<p>Le problème porte sur <code>__MyCompanyName__</code>. Il serait bien plus propre de le remplacer par une valeur personnalisée (et automatique de préférence). Pour ceci, Apple a tout prévu &#8230;<br />
<span id="more-707"></span><br />
Il suffit tout simplement de modifier <code>ORGANIZATIONNAME</code> de <code>PBXCustomTemplateMacroDefinitions</code> dans la configuration de Xcode. En ligne de commande, ça donne (dans mon cas):</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p707code12'); return false;">View Code</a> TEXT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p70712"><td class="code" id="p707code12"><pre class="text" style="font-family:monospace;">defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions {&quot;ORGANIZATIONNAME&quot;=&quot;Julien Quéré - http://webd.fr&quot;;}'</pre></td></tr></table></div>

<p><!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/707-developpement-iphone-modifier-le-__mycompanyname__/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redimensionner une UIImage en étant Threadsafe</title>
		<link>http://webd.fr/631-redimensionner-une-uiimage-en-etant-threadsafe</link>
		<comments>http://webd.fr/631-redimensionner-une-uiimage-en-etant-threadsafe#comments</comments>
		<pubDate>Sat, 30 May 2009 07:47:26 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Pro]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=631</guid>
		<description><![CDATA[Il y a peu, je vous présentais ici même comment redimensionner une UIImage. Je vous replace dans le contexte: Dans certains cas, il peut être utile de redimensionner une UIImage. En effet, même si UIImageView gère très bien le redimensionnement, &#8230; <a href="http://webd.fr/631-redimensionner-une-uiimage-en-etant-threadsafe">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Il y a peu, je vous présentais ici même comment <a href="http://webd.fr/320-redimensionner-une-uiimage">redimensionner une <code>UIImage</code></a>. Je vous replace dans le contexte: <cite>Dans certains cas, il peut être utile de redimensionner une <code>UIImage</code>. En effet, même si <code>UIImageView</code> gère très bien le redimensionnement, on peut vouloir exporter une image dans une certaine taille. De même, il n’est pas forcement utile de stocker (en mémoire ou bien en dur) une image de grande taille si c’est pour l’afficher réduite par la suite</cite>.</p>
<p>Le code qui était présenté est fonctionnel … Oui, mais un collègue m&#8217;a fait remarquer que ce n&#8217;était pas le cas en multi-threads. Pourquoi ? Tout simplement parce que quand on fait <code>UIGraphicsBeginImageContext()</code>, on travaille dans un contexte unique. Ainsi, quand on voudra redimensionner deux images en même temps, elles partageront le même contexte. Clairement, ça ne peut pas marcher. D&#8217;ailleurs: ça ne marche pas !</p>
<p><span id="more-631"></span></p>
<p>Partant de là il y a deux options: soit on gère un système de sémaphore, soit on trouve un moyen de créer un contexte spécifique. L&#8217;idée du sémaphore est à exclure d&#8217;emblée. Ceci pour la simple et bonne raison qu&#8217;elle nous enlève l&#8217;avantage principal d&#8217;utiliser des threads: pouvoir exécuter des opérations en simultané. </p>
<p>Il faut donc créer un contexte bitmap spécifique à notre thread. Ensuite, on dessine notre image à redimensionner dans ce contexte que l&#8217;on vient de créer. Pour finir, on n&#8217;oubliera pas de libérer les différents refs créées. Dans le code, voilà ce que cela donne:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p631code15'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p63115"><td class="code" id="p631code15"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//  UIImageAdditions.m</span>
<span style="color: #11740a; font-style: italic;">//  Untitled</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Julien on 28/05/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 Julien Quéré - Webd.fr. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;UIImageAdditions.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> UIImage<span style="color: #002200;">&#40;</span>UIImageAdditions<span style="color: #002200;">&#41;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>UIImage <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>resizeWithSize<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGSize<span style="color: #002200;">&#41;</span>size <span style="color: #002200;">&#123;</span>
	CGColorSpaceRef colorSpace <span style="color: #002200;">=</span> CGColorSpaceCreateDeviceRGB<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
	CGContextRef context <span style="color: #002200;">=</span> CGBitmapContextCreate<span style="color: #002200;">&#40;</span><span style="color: #a61390;">NULL</span>, size.width, size.height, <span style="color: #2400d9;">5</span>, size.width<span style="color: #002200;">*</span><span style="color: #2400d9;">2</span>, colorSpace, kCGImageAlphaNoneSkipFirst<span style="color: #002200;">&#41;</span>; <span style="color: #11740a; font-style: italic;">//5bpc </span>
	<span style="color: #11740a; font-style: italic;">// size.width*2 = 2bbp</span>
	CGRect rect <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, size.width, size.height<span style="color: #002200;">&#41;</span>;
&nbsp;
	CGContextDrawImage<span style="color: #002200;">&#40;</span>context, rect, self.CGImage<span style="color: #002200;">&#41;</span>;
	CGImageRef refNewImage <span style="color: #002200;">=</span> CGBitmapContextCreateImage<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;
	UIImage <span style="color: #002200;">*</span>newImage <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIImage imageWithCGImage<span style="color: #002200;">:</span>refNewImage<span style="color: #002200;">&#93;</span>;
&nbsp;
	CGImageRelease<span style="color: #002200;">&#40;</span>refNewImage<span style="color: #002200;">&#41;</span>;
	CGColorSpaceRelease<span style="color: #002200;">&#40;</span>colorSpace<span style="color: #002200;">&#41;</span>;
	CGContextRelease<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #a61390;">return</span> newImage;	
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #11740a; font-style: italic;">//  UIImageAdditions.h</span>
<span style="color: #11740a; font-style: italic;">//  Untitled</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Julien on 28/05/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 Julien Quéré - Webd.fr. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &lt;Foundation/Foundation.h&gt;</span>
&nbsp;
&nbsp;
<span style="color: #a61390;">@interface</span> UIImage<span style="color: #002200;">&#40;</span>UIImageAdditions<span style="color: #002200;">&#41;</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>UIImage <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>resizeWithSize<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGSize<span style="color: #002200;">&#41;</span>size;
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>

<p>Pour l&#8217;utilisation de <code>CGBitmapContextCreate</code>, référez vous à <a href="http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Reference/CGBitmapContext/Reference/reference.html#//apple_ref/doc/uid/TP30000947-CH1g-F16989">la littérature Apple sur le sujet</a>. La seule chose qui aurait besoin d&#8217;être explicité c&#8217;est le premier paramètre: le <code>NULL</code>. Le premier paramètre correspond à un pointeur où les données du contexte doivent être stockées. Quand on passe <code>NULL</code>, on indique en fait que l&#8217;on se fiche d&#8217;où les données seront stockées (ce qui est notre cas).</p>
<p>Une fois l&#8217;addition de <code>UIImage</code> mise en place, l&#8217;utilisation du code est assez simple:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p631code16'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p63116"><td class="code" id="p631code16"><pre class="objc" style="font-family:monospace;">	UIImage <span style="color: #002200;">*</span>myPic <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;poney.jpg&quot;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>myPic resizeWithSize<span style="color: #002200;">:</span>CGSizeMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">50</span>, <span style="color: #2400d9;">50</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>im setImage<span style="color: #002200;">:</span>myPic<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//im is an UIImageView</span></pre></td></tr></table></div>

<p>Merci à Loïc Dardant pour le code et le coup de main.<br />
<!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/631-redimensionner-une-uiimage-en-etant-threadsafe/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calculer un hash MD5</title>
		<link>http://webd.fr/636-calculer-un-hash-md5</link>
		<comments>http://webd.fr/636-calculer-un-hash-md5#comments</comments>
		<pubDate>Tue, 19 May 2009 07:14:56 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=636</guid>
		<description><![CDATA[Pour ceux qui ne la connaissent pas, MD5 est une méthode permettant d&#8217;obtenir une empreinte numérique unique d&#8217;un message (au sens large du terme: chaine de caractère ou fichier). Cet algorithme a longtemps été utilisé à des fins de sécurité. &#8230; <a href="http://webd.fr/636-calculer-un-hash-md5">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Pour ceux qui ne la connaissent pas, MD5 est une méthode permettant d&#8217;obtenir une empreinte numérique unique d&#8217;un message (au sens large du terme: chaine de caractère ou fichier). Cet algorithme a longtemps été utilisé à des fins de sécurité. Au risque de me répéter: <strong>n&#8217;utilisez pas MD5 à des fins de sécurité</strong> ! Cet algorithme est maintenant faible. Plus d&#8217;informations sur <a href="http://en.wikipedia.org/wiki/MD5#Vulnerability">Wikipedia EN</a>.</p>
<p>MD5 peut être utilisé pour générer une clef &laquo;&nbsp;<i>unique</i>&nbsp;&raquo; à partir d&#8217;une chaine de caractères. Exemple concret: j&#8217;ai des objets représentant des rendez-vous qui naviguent un peu partout (SQLite local, serveur de calendrier distant, &#8230;). Il me faut à tout moment pouvoir identifier uniquement un rendez-vous. La solution que j&#8217;ai choisi est de générer une somme MD5 à partir du titre du rendez-vous, de la date de création et l&#8217;UDID (voir <a href="http://webd.fr/526-astuces-developpement-iphone-6-recuperer-ludid"><em>Comment récupérer l’UDID</em></a>). Voici l&#8217;implémentation que j&#8217;utilise pour générer mes MD5 (dans le cas présent, c&#8217;est une addition de <code>NSString</code>):<br />
<span id="more-636"></span></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p636code20'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p63620"><td class="code" id="p636code20"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  NSStringAdditions.h</span>
<span style="color: #11740a; font-style: italic;">//  iMeeting</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Julien on 12/05/09.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &lt;Foundation/Foundation.h&gt;</span>
<span style="color: #6e371a;">#import &lt;CommonCrypto/CommonDigest.h&gt;</span>
&nbsp;
&nbsp;
<span style="color: #a61390;">@interface</span> <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">&#40;</span>NSStringAdditions<span style="color: #002200;">&#41;</span>  
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>md5Hash;
&nbsp;
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p636code21'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p63621"><td class="code" id="p636code21"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  NSStringAdditions.m</span>
<span style="color: #11740a; font-style: italic;">//  iMeeting</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Julien on 12/05/09.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;NSStringAdditions.h&quot;</span>
&nbsp;
&nbsp;
<span style="color: #a61390;">@implementation</span>  <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">&#40;</span>NSStringAdditions<span style="color: #002200;">&#41;</span>  
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>md5Hash
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">const</span> <span style="color: #a61390;">char</span> <span style="color: #002200;">*</span>cStr <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self UTF8String<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">unsigned</span> <span style="color: #a61390;">char</span> result<span style="color: #002200;">&#91;</span>CC_MD5_DIGEST_LENGTH<span style="color: #002200;">&#93;</span>;
	CC_MD5<span style="color: #002200;">&#40;</span> cStr, <a href="http://www.opengroup.org/onlinepubs/009695399/functions/strlen.html"><span style="color: #a61390;">strlen</span></a><span style="color: #002200;">&#40;</span>cStr<span style="color: #002200;">&#41;</span>, result <span style="color: #002200;">&#41;</span>;
	<span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X&quot;</span>,
			result<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>, result<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>, result<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span>, result<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">3</span><span style="color: #002200;">&#93;</span>, result<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">4</span><span style="color: #002200;">&#93;</span>, result<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">5</span><span style="color: #002200;">&#93;</span>, result<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">6</span><span style="color: #002200;">&#93;</span>, result<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">7</span><span style="color: #002200;">&#93;</span>,
			result<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">8</span><span style="color: #002200;">&#93;</span>, result<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">9</span><span style="color: #002200;">&#93;</span>, result<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">10</span><span style="color: #002200;">&#93;</span>, result<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">11</span><span style="color: #002200;">&#93;</span>, result<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">12</span><span style="color: #002200;">&#93;</span>, result<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">13</span><span style="color: #002200;">&#93;</span>, result<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">14</span><span style="color: #002200;">&#93;</span>, result<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">15</span><span style="color: #002200;">&#93;</span>
			<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>

<p>Et un exemple simple d&#8217;utilisation:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p636code22'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p63622"><td class="code" id="p636code22"><pre class="objc" style="font-family:monospace;"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>maChaine <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> stringWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MaChaineAMoi&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">:</span>
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>monMd5 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>maChaine md5Hash<span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p><!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/636-calculer-un-hash-md5/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Astuces développement iPhone 7: Deux NSDate sont-elles du même jour ?</title>
		<link>http://webd.fr/586-astuces-developpement-iphone-nsdate-comparaison-jour</link>
		<comments>http://webd.fr/586-astuces-developpement-iphone-nsdate-comparaison-jour#comments</comments>
		<pubDate>Fri, 15 May 2009 07:06:42 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Astuce]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=586</guid>
		<description><![CDATA[Voilà un problème simple qui s&#8217;est posé lors d&#8217;un de mes développement: comme vérifier si deux dates sont bien le même jour ? Ceci, en gardant les notions de fuseau horaires et compagnie. Bien que le problème soit simple, la &#8230; <a href="http://webd.fr/586-astuces-developpement-iphone-nsdate-comparaison-jour">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Voilà un problème simple qui s&#8217;est posé lors d&#8217;un de mes développement: comme vérifier si deux dates sont bien le même jour ? Ceci, en gardant les notions de fuseau horaires et compagnie. Bien que le problème soit simple, la solution n&#8217;est pas si anodine que cela.<br />
<span id="more-586"></span><br />
Il s&#8217;agit, dans un premier temps, de préciser dans quel calendrier on se situe. Ici, on est tout simple dans le calendrier <code>NSGregorianCalendar</code>. Ensuite, on extrait le composant de la date qui nous intéresse (ici: le jour). Puis, il ne reste plus qu&#8217;a comparer les deux composants extraits pour déterminer si les deux <code>NSDate</code> sont bien le même jour. </p>
<p>Voici la méthode qui fait cela (en étendant <code>NSDate</code> au passage) et l&#8217;utilisation: </p>
<p>Ajoute dans la classe NSDate en dérivant</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p586code26'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p58626"><td class="code" id="p586code26"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Le .h</span>
<span style="color: #6e371a;">#import &lt;Foundation/Foundation.h&gt;</span>
&nbsp;
&nbsp;
<span style="color: #a61390;">@interface</span> <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/"><span style="color: #400080;">NSDate</span></a> <span style="color: #002200;">&#40;</span>NSDateAdditions<span style="color: #002200;">&#41;</span> 
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> isTheSameDayAsThisDate<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/"><span style="color: #400080;">NSDate</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>date;
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p586code27'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p58627"><td class="code" id="p586code27"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Le .m</span>
<span style="color: #a61390;">@implementation</span> <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/"><span style="color: #400080;">NSDate</span></a> <span style="color: #002200;">&#40;</span>NSDateAdditions<span style="color: #002200;">&#41;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> isTheSameDayAsThisDate<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/"><span style="color: #400080;">NSDate</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>date <span style="color: #002200;">&#123;</span>
	<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSCalendar_Class/"><span style="color: #400080;">NSCalendar</span></a> <span style="color: #002200;">*</span>gregorian <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSCalendar_Class/"><span style="color: #400080;">NSCalendar</span></a> alloc<span style="color: #002200;">&#93;</span>	initWithCalendarIdentifier<span style="color: #002200;">:</span>NSGregorianCalendar<span style="color: #002200;">&#93;</span>;
	<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDateComponents_Class/"><span style="color: #400080;">NSDateComponents</span></a> <span style="color: #002200;">*</span>comps1 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>gregorian components<span style="color: #002200;">:</span>NSDayCalendarUnit fromDate<span style="color: #002200;">:</span>date<span style="color: #002200;">&#93;</span>;
	<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDateComponents_Class/"><span style="color: #400080;">NSDateComponents</span></a> <span style="color: #002200;">*</span>comps2 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>gregorian components<span style="color: #002200;">:</span>NSDayCalendarUnit fromDate<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>gregorian release<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">return</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>comps1 isEqual<span style="color: #002200;">:</span>comps2<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p586code28'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p58628"><td class="code" id="p586code28"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// startDate et endDate étant deux NSDate</span>
<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>startDate isTheSameDayAsThisDate<span style="color: #002200;">:</span>endDate<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;startDate et endDate sont le même jour&quot;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p><!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/586-astuces-developpement-iphone-nsdate-comparaison-jour/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Astuces développement iPhone 6: Récupérer l&#8217;UDID</title>
		<link>http://webd.fr/526-astuces-developpement-iphone-6-recuperer-ludid</link>
		<comments>http://webd.fr/526-astuces-developpement-iphone-6-recuperer-ludid#comments</comments>
		<pubDate>Mon, 11 May 2009 09:14:54 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Astuce]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=526</guid>
		<description><![CDATA[Il peut être utile, dans une application, de connaître l'UDID de façon logicielle. Ainsi, on identifie de façon unique et certaine l'équipement sur lequel notre application s'exécute. Pour récupérer l'UDID, rien de plus simple ... <a href="http://webd.fr/526-astuces-developpement-iphone-6-recuperer-ludid">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>L&#8217;UDID (<i>Universal Device Identifier</i>) d&#8217;un iPhone est, comme son nom l&#8217;indique, un identifiant unique pour chaque iPhone / iPod. Si vous avez déjà eu à générer des fichiers de provisioning, vous connaissez bien cet identifiant. En effet, c&#8217;est ce dernier que l&#8217;on doit transmettre à Apple quand on veut rajouter un iPhone / iPod dans la liste des appareils autorisés pour un développement ou une distribution. </p>
<p>Il peut être utile, dans une application, de connaître ce fameux UDID de façon logicielle. Ainsi, on identifie de façon unique et certaine l&#8217;équipement sur lequel notre application s&#8217;exécute. Pour récupérer l&#8217;UDID, rien de plus simple:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p526code29'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p52629"><td class="code" id="p526code29"><pre class="objc" style="font-family:monospace;"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>udid <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIDevice currentDevice<span style="color: #002200;">&#93;</span> uniqueIdentifier<span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p><!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/526-astuces-developpement-iphone-6-recuperer-ludid/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Astuces développement iPhone 5: whatis et ptype</title>
		<link>http://webd.fr/388-astuces-developpement-iphone-5-whatis-et-ptype</link>
		<comments>http://webd.fr/388-astuces-developpement-iphone-5-whatis-et-ptype#comments</comments>
		<pubDate>Wed, 06 May 2009 09:02:38 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Astuce]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=388</guid>
		<description><![CDATA[Dans la même veine que le Print Object en console, voici une nouvelle astuce en console de debug. L&#8217;idée n&#8217;est plus de récupérer la description d&#8217;un objet, mais son type. Ainsi, il y a deux commandes: whatis et ptype. La &#8230; <a href="http://webd.fr/388-astuces-developpement-iphone-5-whatis-et-ptype">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Dans la même veine que le <a href="http://webd.fr/385-astuces-developpement-iphone-2-print-object-en-console">Print Object en console</a>, voici une nouvelle astuce en console de debug. L&#8217;idée n&#8217;est plus de récupérer la description d&#8217;un objet, mais son type. Ainsi, il y a deux commandes: <code>whatis</code> et <code>ptype</code>. La première permets d&#8217;avoir simplement le type d&#8217;un objet. Ainsi, si on a un objet <code>monDico</code> de type <code>NSMutableDictionary</code>, voilà ce que l&#8217;on obtient avec <code>whatis</code>:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p388code34'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p38834"><td class="code" id="p388code34"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#40;</span>gdb<span style="color: #002200;">&#41;</span> whatis monDico
type <span style="color: #002200;">=</span> <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/"><span style="color: #400080;">NSMutableDictionary</span></a> <span style="color: #002200;">*</span></pre></td></tr></table></div>

<p><code>ptype</code>, quant à lui est beaucoup plus complet. Si on reprends le même exemple, voilà ce que l&#8217;on obtient:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p388code35'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p38835"><td class="code" id="p388code35"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#40;</span>gdb<span style="color: #002200;">&#41;</span> ptype monDico
type <span style="color: #002200;">=</span> class <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/"><span style="color: #400080;">NSMutableDictionary</span></a> <span style="color: #002200;">:</span> public <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/"><span style="color: #400080;">NSDictionary</span></a> <span style="color: #002200;">&#123;</span>
<span style="color: #002200;">&#125;</span> <span style="color: #002200;">*</span></pre></td></tr></table></div>

<p>Là où <code>ptype</code> prends tout son intérêt, c&#8217;est sur les types personnalisés. Voici deux exemple concret avec des objet perso:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p388code36'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p38836"><td class="code" id="p388code36"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#40;</span>gdb<span style="color: #002200;">&#41;</span> ptype currentRdv
type <span style="color: #002200;">=</span> class MiniRdv <span style="color: #002200;">:</span> public <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/"><span style="color: #400080;">NSObject</span></a> <span style="color: #002200;">&#123;</span>
  protected<span style="color: #002200;">:</span>
    <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>startDateFormated;
    <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>startTimeFormated;
    <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>title;
    <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>personName;
    <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>personFirstName;
    <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>personPhoneBookId;
    NSInteger dbId;
<span style="color: #002200;">&#125;</span> <span style="color: #002200;">*</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p388code37'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p38837"><td class="code" id="p388code37"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#40;</span>gdb<span style="color: #002200;">&#41;</span> ptype cell
type <span style="color: #002200;">=</span> class RdvTableCell <span style="color: #002200;">:</span> public UITableViewCell <span style="color: #002200;">&#123;</span>
  protected<span style="color: #002200;">:</span>
    MiniRdv <span style="color: #002200;">*</span>miniRdvObject;
    UILabel <span style="color: #002200;">*</span>topLeftLabel;
    UILabel <span style="color: #002200;">*</span>bottomLeftLabel;
    UILabel <span style="color: #002200;">*</span>bottomRightLabel;
    UILabel <span style="color: #002200;">*</span>topRightLabel;
    UIImageView <span style="color: #002200;">*</span>avatar;
<span style="color: #002200;">&#125;</span> <span style="color: #002200;">*</span></pre></td></tr></table></div>

<p>Bref, <code>ptype</code> est un outil indispensable au debug d&#8217;applications !<!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/388-astuces-developpement-iphone-5-whatis-et-ptype/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Astuces développement iPhone 4: Récupérer le nom de l&#8217;iPhone</title>
		<link>http://webd.fr/420-astuces-developpement-iphone-4-recuperer-le-nom-de-liphone</link>
		<comments>http://webd.fr/420-astuces-developpement-iphone-4-recuperer-le-nom-de-liphone#comments</comments>
		<pubDate>Fri, 01 May 2009 07:56:02 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Astuce]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=420</guid>
		<description><![CDATA[Il peut être très utile de récupérer le nom de l&#8217;iPhone sur lequel notre application s&#8217;exécute (comme iPhone-de-julien). C&#8217;est le cas notamment dans des applications où on appaire deux iPhone au travers d&#8217;un réseau WiFi (par exemple). L&#8217;idée est très &#8230; <a href="http://webd.fr/420-astuces-developpement-iphone-4-recuperer-le-nom-de-liphone">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Il peut être très utile de récupérer le nom de l&#8217;iPhone sur lequel notre application s&#8217;exécute (comme <cite>iPhone-de-julien</cite>). C&#8217;est le cas notamment dans des applications où on appaire deux iPhone au travers d&#8217;un réseau WiFi (par exemple). L&#8217;idée est très simple: on récupère les informations de l&#8217;hôte courant, puis on prend le premier de ses noms. Ce qui donne au final:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p420code39'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p42039"><td class="code" id="p420code39"><pre class="objc" style="font-family:monospace;"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>deviceName <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSHost_Class/"><span style="color: #400080;">NSHost</span></a> currentHost<span style="color: #002200;">&#93;</span> names<span style="color: #002200;">&#93;</span> objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p><!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/420-astuces-developpement-iphone-4-recuperer-le-nom-de-liphone/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Astuces développement iPhone 3: Executer un code seulement sur le simulateur</title>
		<link>http://webd.fr/415-iphone-executer-code-seulement-le-simulateur</link>
		<comments>http://webd.fr/415-iphone-executer-code-seulement-le-simulateur#comments</comments>
		<pubDate>Mon, 27 Apr 2009 09:14:00 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Astuce]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=415</guid>
		<description><![CDATA[Il peut être utile parfois de n&#8217;exécuter certains codes que dans le simulateur (ou à l&#8217;inverse: seulement sur un véritable iPhone). Concrètement, c&#8217;est le cas quand on utilise des fonctionnalités non présentes sur le simulateur (accéléromètre par exemple). Pour ce &#8230; <a href="http://webd.fr/415-iphone-executer-code-seulement-le-simulateur">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Il peut être utile parfois de n&#8217;exécuter certains codes que dans le simulateur (ou à l&#8217;inverse: seulement sur un véritable iPhone). Concrètement, c&#8217;est le cas quand on utilise des fonctionnalités non présentes sur le simulateur (accéléromètre par exemple). Pour ce faire, il suffit d&#8217;inclure le code a exécuter sur simulateur entre des directives de compilateur:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p415code41'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p41541"><td class="code" id="p415code41"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#if TARGET_IPHONE_SIMULATOR</span>
  NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Bonjour, je suis sir le simulateur&quot;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #6e371a;">#else</span>
  NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Bonjour, je suis sur un véritable iPhone !&quot;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #6e371a;">#endif</span></pre></td></tr></table></div>

<p><!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/415-iphone-executer-code-seulement-le-simulateur/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Astuces développement iPhone 2: Print Object en console</title>
		<link>http://webd.fr/385-astuces-developpement-iphone-2-print-object-en-console</link>
		<comments>http://webd.fr/385-astuces-developpement-iphone-2-print-object-en-console#comments</comments>
		<pubDate>Mon, 20 Apr 2009 08:30:24 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Astuce]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=385</guid>
		<description><![CDATA[Je me suis très souvent posé la question suivante: Mais pourquoi ça ne marche pas ? Qu&#8217;est ce qu&#8217;il y a dans cet objet ?. Le fait est que ce n&#8217;est pas très facile de répondre à cette question avec &#8230; <a href="http://webd.fr/385-astuces-developpement-iphone-2-print-object-en-console">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Je me suis très souvent posé la question suivante: <cite>Mais pourquoi ça ne marche pas ? Qu&#8217;est ce qu&#8217;il y a dans cet objet ?</cite>. Le fait est que ce n&#8217;est pas très facile de répondre à cette question avec l&#8217;interface de débogage de Xcode. Par contre dans la console de debug, il y a une commande magnifique … </p>
<p>Il s&#8217;agit tout simplement de <code>po</code> (pour <i>Print Object</i>). Pour l&#8217;utiliser, rien de plus simple: mettez un point d&#8217;arrêt là où vous voulez voir ce que contient un objet. Ensuite, faites un simple <code>po monObjet</code>. Par exemple, créons un <code>NSMutableDictionary</code> …</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p385code44'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p38544"><td class="code" id="p385code44"><pre class="objc" style="font-family:monospace;"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/"><span style="color: #400080;">NSMutableDictionary</span></a> <span style="color: #002200;">*</span> monDico <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/"><span style="color: #400080;">NSMutableDictionary</span></a> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>monDico setObject<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;objet1&quot;</span> forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;clef1&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>monDico setObject<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;objet2&quot;</span> forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;clef2&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>monDico setObject<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;objet3&quot;</span> forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;clef3&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>monDico setObject<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;objet4&quot;</span> forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;clef4&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>monDico setObject<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;objet5&quot;</span> forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;clef5&quot;</span><span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p>Et voilà ce que nous renvoie la console après un <code>po monDico</code></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p385code45'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p38545"><td class="code" id="p385code45"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#40;</span>gdb<span style="color: #002200;">&#41;</span> po monDico
<span style="color: #002200;">&#123;</span>
    clef1 <span style="color: #002200;">=</span> objet1;
    clef2 <span style="color: #002200;">=</span> objet2;
    clef3 <span style="color: #002200;">=</span> objet3;
    clef4 <span style="color: #002200;">=</span> objet4;
    clef5 <span style="color: #002200;">=</span> objet5;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>En fait, <code>po</code> fait appel à la méthode <code>description</code> de l&#8217;objet. Toutes les classes Cocoa de base implémentent cette méthode. Pour les classes personnelles, il vous suffit d&#8217;implémenter le protocole suivant: <code>- (NSString *)description;</code>.<!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/385-astuces-developpement-iphone-2-print-object-en-console/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Astuces développement iPhone 1: Quelques raccourcis claviers</title>
		<link>http://webd.fr/378-astuces-developpement-iphone-1-quelques-raccourcis-claviers</link>
		<comments>http://webd.fr/378-astuces-developpement-iphone-1-quelques-raccourcis-claviers#comments</comments>
		<pubDate>Mon, 13 Apr 2009 09:06:59 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Astuce]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=378</guid>
		<description><![CDATA[Au cours de mes développements iPhone, il y a plein de petites astuces que je découvre. Des petites choses toute bêtes, mais elles peuvent faire gagner pas mal de temps et de confort quand on les utilise les uns à &#8230; <a href="http://webd.fr/378-astuces-developpement-iphone-1-quelques-raccourcis-claviers">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Au cours de mes développements iPhone, il y a plein de petites astuces que je découvre. Des petites choses toute bêtes, mais elles peuvent faire gagner pas mal de temps et de confort quand on les utilise les uns à la suite des autres. Voilà pourquoi je pense lancer une série de billets où je présenterais les astuces découvertes au fil du temps. </p>
<p>Commençons donc par quelques raccourcis claviers découverts récemment qui me font gagner pas mal de temps: </p>
<ul>
<li><b>Option et double clic</b>: affiche la documentation pour ce qui se trouve sous le curseur (si la documentation existe bien évidement). </li>
<li><b>Commande et double clic</b>: envoie vers la définition (dans le .h) de ce qui se trouve sous le curseur.</li>
<li><b>Commande-Option-Haut</b>: permets de switcher entre le fichier d&#8217;en-tête (.h) et de code (.m) et vice-versa.</li>
<li><b>Commande-B</b>: lance la compilation du projet.</li>
<li><b>Commande-Retour</b>: compile le projet et le lance.</li>
</ul>
<p>Sinon, pour ceux qui veulent un grand poster, il y a l&#8217;image faite par <a href="http://cocoasamurai.blogspot.com/2008/02/complete-xcode-keyboard-shortcut-list.html">Colin Wheeler de Cocoa Samurai</a>. Elle est très (trop ?) complète:</p>
<p><a href="http://webd.fr/wp-content/uploads/2009/04/xcode-shortcuts.png" rel="lightbox[378]" title="xcode-shortcuts"><img src="http://webd.fr/wp-content/uploads/2009/04/xcode-shortcuts-290x300.png" alt="xcode-shortcuts" title="xcode-shortcuts" width="290" height="300" class="aligncenter size-medium wp-image-381" /></a></p>
<p>A bientôt (certainement) pour de nouvelles astuces … </p>
<p><!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/378-astuces-developpement-iphone-1-quelques-raccourcis-claviers/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Redimensionner une UIImage</title>
		<link>http://webd.fr/320-redimensionner-une-uiimage</link>
		<comments>http://webd.fr/320-redimensionner-une-uiimage#comments</comments>
		<pubDate>Fri, 27 Feb 2009 15:14:04 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Pro]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=320</guid>
		<description><![CDATA[Dans certains cas, il peut être utile de redimensionner une UIImage. En effet, même si UIImageView gère très bien le redimensionnement, on peut vouloir exporter une image dans une certaine taille. De même, il n&#8217;est pas forcement utile de stocker &#8230; <a href="http://webd.fr/320-redimensionner-une-uiimage">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Dans certains cas, il peut être utile de redimensionner une <code>UIImage</code>. En effet, même si <code>UIImageView</code> gère très bien le redimensionnement, on peut vouloir exporter une image dans une certaine taille. De même, il n&#8217;est pas forcement utile de stocker (en mémoire ou bien en dur) une image de grande taille si c&#8217;est pour l&#8217;afficher réduite par la suite. </p>
<p>Pour redimensionner une image, c&#8217;est plutôt simple ! L&#8217;idée est de créer un contexte d&#8217;image de la taille souhaitée (ici 40*40 pixels). Dans ce contexte, en dessine l&#8217;image à redimensionner dans la taille souhaitée. Il ne reste alors plus qu&#8217;à récupérer l&#8217;image redimensionnée avec un <code>UIGraphicsGetImageFromCurrentImageContext</code>. Pour finir, on pensera bien à fermer le contexte courant. </p>
<p>Voici le code final:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p320code47'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p32047"><td class="code" id="p320code47"><pre class="objc" style="font-family:monospace;">CGSize size <span style="color: #002200;">=</span> CGSizeMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">40</span>, <span style="color: #2400d9;">40</span><span style="color: #002200;">&#41;</span>;
UIGraphicsBeginImageContext<span style="color: #002200;">&#40;</span> size <span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#91;</span>avatarImage drawInRect<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>,<span style="color: #2400d9;">0</span>,size.width,size.height<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
avatarImage <span style="color: #002200;">=</span> UIGraphicsGetImageFromCurrentImageContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
UIGraphicsEndImageContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;</pre></td></tr></table></div>

<p><!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/320-redimensionner-une-uiimage/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Désactiver les NSLog en release</title>
		<link>http://webd.fr/307-desactiver-les-nslog-en-release</link>
		<comments>http://webd.fr/307-desactiver-les-nslog-en-release#comments</comments>
		<pubDate>Fri, 20 Feb 2009 15:28:09 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Pro]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=307</guid>
		<description><![CDATA[Le NSLog est l&#8217;outil de base dans le développement et le déboguage d&#8217;application Cocoa (donc Cocoa Touch). Seulement, l&#8217;utilisation de NSLog n&#8217;est pas si anodine qu&#8217;elle peut paraître … Le fait d&#8217;envoyer une chaine de caractère à la sortie console &#8230; <a href="http://webd.fr/307-desactiver-les-nslog-en-release">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Le <code>NSLog</code> est l&#8217;outil de base dans le développement et le déboguage d&#8217;application Cocoa (donc Cocoa Touch). Seulement, l&#8217;utilisation de <code>NSLog</code> n&#8217;est pas si anodine qu&#8217;elle peut paraître … Le fait d&#8217;envoyer une chaine de caractère à la sortie console consomme des ressources. </p>
<p>Certes, c&#8217;est peu de choses, mais quand un <code>NSLog</code> est inclus dans une boucle, se déclenche à chaque <code>touchesMoved:</code> (par exemple), il commence à ralentir très sérieusement le fonctionnement de l&#8217;application. Sans compter qu&#8217;une fois l&#8217;application distribuée, il est possible pour l&#8217;utilisateur final de lire ce qui se trouve dans les logs … Ce qui n&#8217;est pas forcement voulu pour le développeur. </p>
<p>L&#8217;idée serait donc, quand on est en configuration de compilation « release », de désactiver (automatiquement les <code>NSLog</code>). <span id="more-307"></span>Pour ce faire, on va simplement ajouter le code suivant dans <code>leNomDeLApplication_Prefix.pch</code> (il s&#8217;agit simplement d&#8217;un fichier qui est inclus dans tous les fichiers d&#8217;un projet):</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p307code49'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p30749"><td class="code" id="p307code49"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#ifndef DEBUG</span>
<span style="color: #6e371a;">#define NSLog //</span>
<span style="color: #6e371a;">#endif</span></pre></td></tr></table></div>

<p>Le code veut simplement dire: <cite>Si <code>DEBUG</code> n&#8217;est pas activé, on remplace les <code>NSLog</code> par des commentaires</cite>. On pensera donc à ajouter un flag <code>DEBUG</code> dans <code>GCC_PREPROCESSOR_DEFINITIONS</code> de la configuration de compilation dans le mode <code>Debug</code>. Notez que, par défaut, <code>GCC_PREPROCESSOR_DEFINITIONS</code> n&#8217;existe pas, il faudra donc le créer à la main. </p>
<p><a href="http://webd.fr/wp-content/uploads/2009/02/disablenslogscreen.png" rel="lightbox[307]" title="disablenslogscreen"><img src="http://webd.fr/wp-content/uploads/2009/02/disablenslogscreen-281x300.png" alt="disablenslogscreen" title="disablenslogscreen" width="281" height="300" class="aligncenter size-medium wp-image-308" /></a></p>
<p>Voilà, c&#8217;est fini <img src='http://webd.fr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Notez tout de même que cette façon de faire a une limitation: il faut que les <code>NSLog</code> soient définis sur une seule ligne. Mais bon, ça l&#8217;est dans 99% des cas ! <!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/307-desactiver-les-nslog-en-release/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Iphonelite3: Une nouvelle librairie SQLite pour iPhone</title>
		<link>http://webd.fr/288-iphonelite3-une-nouvelle-librairie-sqlite-pour-iphone</link>
		<comments>http://webd.fr/288-iphonelite3-une-nouvelle-librairie-sqlite-pour-iphone#comments</comments>
		<pubDate>Thu, 29 Jan 2009 20:32:18 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Pro]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=288</guid>
		<description><![CDATA[Je viens de découvrir aujourd&#8217;hui une nouvelle librairie permettant de simplifier l&#8217;utilisation de SQLite3 sur iPhone: Iphonelite3. L&#8217;idée global du projet est de ne pas avoir à coder une seule ligne de SQL dans son application. Il s&#8217;agit tout bêtement &#8230; <a href="http://webd.fr/288-iphonelite3-une-nouvelle-librairie-sqlite-pour-iphone">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Je viens de découvrir aujourd&#8217;hui une nouvelle librairie permettant de simplifier l&#8217;utilisation de SQLite3 sur iPhone: Iphonelite3. L&#8217;idée global du projet est de ne pas avoir à coder une seule ligne de SQL dans son application. Il s&#8217;agit tout bêtement de faire de la persistance d&#8217;objet. Là où le concept est intéressant, c&#8217;est qu&#8217;il ne se base pas sur des objets héritant d&#8217;une quelconque implémentation de serialisation. </p>
<p>Non, l&#8217;idée est plus axée « hibernate » (que l&#8217;on trouve avec Java). Vous passez votre objet au gestionnaire de base de données et il s&#8217;occupe de tout le reste. Je ne vais pas continuer à faire l&#8217;article de Iphonelite3, son auteur le fait très bien <a href="http://iphonelite3.wordpress.com/">sur son blog dédié</a>. Notez que le projet est, pour le moment, en phase <cite>alpha</cite> et ne doit donc pas être utilisé en phase de production. Mais c&#8217;est à regarder avec attention. </p>
<p>Au passage, je rappellerais ce qui se fait sur ce segment en ce moment. Il y a les projets <a href="http://code.google.com/p/flycode/source/browse/trunk/fmdb">FMDB</a> (que j&#8217;utilise dans deux de mes projets), <a href="http://code.google.com/p/sqlitepersistentobjects/">SQLitePersistentObjects</a> (que je n&#8217;ai pas pu utiliser dans mon dernier projet car il gère mal les <code>NSMutableDictionary</code>) et <a href="http://code.google.com/p/entropydb/">EntropyDB</a>.<!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/288-iphonelite3-une-nouvelle-librairie-sqlite-pour-iphone/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Une UITableView triée par ordre alphabétique</title>
		<link>http://webd.fr/237-une-uitableview-triee-par-ordre-alphabetique</link>
		<comments>http://webd.fr/237-une-uitableview-triee-par-ordre-alphabetique#comments</comments>
		<pubDate>Mon, 26 Jan 2009 07:08:57 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Pro]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=237</guid>
		<description><![CDATA[L&#8217;UITableView est un outil idéal pour afficher une certaine quantité de données à l&#8217;utilisateur. Seulement voilà, quand cette quantité de données devient grande, il peut être intéressant de permettre à l&#8217;utilisateur d&#8217;accéder rapidement à l&#8217;information qu&#8217;il souhaite. Une des solutions &#8230; <a href="http://webd.fr/237-une-uitableview-triee-par-ordre-alphabetique">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>L&#8217;<code>UITableView</code> est un outil idéal pour afficher une certaine quantité de données à l&#8217;utilisateur. Seulement voilà, quand cette quantité de données devient grande, il peut être intéressant de permettre à l&#8217;utilisateur d&#8217;accéder rapidement à l&#8217;information qu&#8217;il souhaite.</p>
<p>Une des solutions est d&#8217;utiliser le tri par ordre alphabétique. C&#8217;est l&#8217;idéal pour l&#8217;affichage de contacts (par exemple). On peut même aller plus loin. Pourquoi simplement se limiter à un tri par ordre alphabétique ? Pourquoi ne pas proposer une catégorisation des entrées en prenant en compte la première lettre de la propriété qui nous intéresse. C&#8217;est ce que nous allons voir dans ce billet. Au final, nous arriverons à ce résultat:</p>
<p><a href="http://webd.fr/wp-content/uploads/2009/01/alphabeticaltableviewfinalscreen.png" rel="lightbox[237]" title="alphabeticaltableviewfinalscreen"><img src="http://webd.fr/wp-content/uploads/2009/01/alphabeticaltableviewfinalscreen-161x300.png" alt="alphabeticaltableviewfinalscreen" title="alphabeticaltableviewfinalscreen" width="161" height="300" class="aligncenter size-medium wp-image-274" /></a><br />
<span id="more-237"></span></p>
<p>On commence par créer notre projet dans Xcode et on lui ajoute un <code>TableViewController</code>. Pour le moment, on n&#8217;y touche pas. Ensuite, on créée le <code>xib</code> des cellules avec Interface Builder (pour plus de détails sur la manipulation de <code>UITableViewCell</code> avec Interface Builder, voir <a href="http://webd.fr/141-creer-une-uitableviewcell-personnalisee-a-partir-dinterface-builder"><cite>Créer une UITableViewCell personnalisée à partir d’Interface Builder</cite></a>). Maintenant, faisons une structure pour nos données. Ce sera une simple classe contenant 4 propriétés <code>NSString</code>: <code>firstname</code>, <code>lastname</code>, <code>age</code> et <code>sex</code>. Ce qui donne tout simplement:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p237code55'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p23755"><td class="code" id="p237code55"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> Person <span style="color: #002200;">:</span> <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/"><span style="color: #400080;">NSObject</span></a> <span style="color: #002200;">&#123;</span>
    <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>firstname;
    <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>lastname;
    <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>age;
    <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>sex;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>On rajoute aussi les méthodes d&#8217;initialisation et de désallocation de l&#8217;objet:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p237code56'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p23756"><td class="code" id="p237code56"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> initWithLastName<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>mlastname andFirstname<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>mfirstname andSex<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>msex andAge<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>mage <span style="color: #002200;">&#123;</span>
	lastname <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> alloc<span style="color: #002200;">&#93;</span> initWithString<span style="color: #002200;">:</span>mlastname<span style="color: #002200;">&#93;</span>;
	firstname <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> alloc<span style="color: #002200;">&#93;</span> initWithString<span style="color: #002200;">:</span>mfirstname<span style="color: #002200;">&#93;</span>;
	sex <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> alloc<span style="color: #002200;">&#93;</span> initWithString<span style="color: #002200;">:</span>msex<span style="color: #002200;">&#93;</span>;
	age <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> alloc<span style="color: #002200;">&#93;</span> initWithString<span style="color: #002200;">:</span>mage<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</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> dealloc <span style="color: #002200;">&#123;</span>	
	<span style="color: #002200;">&#91;</span>lastname release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>firstname release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>sex release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>age release<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></pre></td></tr></table></div>

<p>Toute la partie <cite>manipulation de données</cite> sera gérée par <code>PersonDataSource</code>. Il s&#8217;agit d&#8217;une classe contenant:</p>
<ul>
<li>un <code>NSArray</code> (<code>personList</code>) qui contiendra notre liste de <code>Person</code> brute (c&#8217;est à dire non-triée)</li>
<li>un <code>NSMutableDictionary</code> (<code>personListAlphabeticalDictionary</code>) qui contiendra nos <code>Person</code> triées par ordre alphabétique. Chaque entrée du dictionnaire aura pour clef la première lettre du nom des <code>Person</code> et en valeur, le tableau de <code>Person</code> correspondant.</li>
<li>un <code>NSArray</code> (<code>personNameFirstLeterIndexArray</code>) qui contiendra la liste de toutes les premières lettres de noms disponibles. En effet, il se peut que l&#8217;on n&#8217;ai aucune entrée avec comme première lettre <cite>Z</cite> (par exemple).</li>
</ul>
<p>Du coté des méthodes, ça donne cela: </p>
<ul>
<li><code>- (void) populate</code>: cette méthode ne fait que récupérer nos objets <code>Person</code>. Dans l&#8217;exemple, j&#8217;ajoute les objets à la main, mais on peut tout à fait remplacer ça par une récupération de données dans un fichier XML ou bien une base de données.</li>
<li><code>- (void) populatePersonListAlphabeticalDictionary</code>: cette méthode va aller chercher le contenu de <code>personList</code> et générer <code>personListAlphabeticalDictionary</code> comme convenu. Pour finir, la méthode va appeler <code>sortPersonInitialLetterIndexes</code>.</li>
<li><code>- (void) sortPersonInitialLetterIndexes</code>: cette méthode va générer <code>personNameIndexArray</code> en récupérant toutes les clefs de <code>personListAlphabeticalDictionary</code> (triées alphabétiquement). Puis pour chacune des clefs, <code>presortPersonListAlphabeticalDictionaryForInitialLetter</code></li>
<li><code>- (void)presortPersonListAlphabeticalDictionaryForInitialLetter:(NSString *)aKey</code> va (pour une clef <code>aKey</code> donnée), trier le contenu du <code>NSArray</code> correspondant dans le <code>personListAlphabeticalDictionary</code>.</li>
<li><code>- (NSArray *)personsWithInitialLetter:(NSString*)aKey</code>: cette méthode retourne un <code>NSArray</code> avec toutes les <code>Person</code> ayant pour première lettre <code>aKey</code>.</li>
<li><code>- (Person *) personForIndexPath:(NSIndexPath *)indexPath</code> retourne l&#8217;objet <code>Person</code> correspondant au <code>NSIndexPath</code> passé en paramètre. Cette méthode sera appelée par le <code>UITableViewController</code>.</li>
</ul>
<p>Au final, on obtient ceci:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p237code57'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p23757"><td class="code" id="p237code57"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> init <span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>self populate<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>self populatePersonListAlphabeticalDictionary<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
&nbsp;
<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> dealloc <span style="color: #002200;">&#123;</span>
&nbsp;
	<span style="color: #002200;">&#91;</span>personList release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>personListAlphabeticalDictionary release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>personNameIndexArray release<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>
&nbsp;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> populate <span style="color: #002200;">&#123;</span>		
	personList <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/"><span style="color: #400080;">NSMutableArray</span></a> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>personList addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Person alloc<span style="color: #002200;">&#93;</span> initWithLastName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Léponge&quot;</span> andFirstname<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Bob&quot;</span> andSex<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Homme&quot;</span> andAge<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;21&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>personList addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Person alloc<span style="color: #002200;">&#93;</span> initWithLastName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Daniel&quot;</span> andFirstname<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Jack&quot;</span> andSex<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Whiskey&quot;</span> andAge<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;12&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>personList addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Person alloc<span style="color: #002200;">&#93;</span> initWithLastName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Fontaine&quot;</span> andFirstname<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Claire&quot;</span> andSex<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Femme&quot;</span> andAge<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;89&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>personList addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Person alloc<span style="color: #002200;">&#93;</span> initWithLastName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Charues&quot;</span> andFirstname<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Vielles&quot;</span> andSex<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Festival&quot;</span> andAge<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;125&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>personList addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Person alloc<span style="color: #002200;">&#93;</span> initWithLastName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Bull&quot;</span> andFirstname<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Red&quot;</span> andSex<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Boisson&quot;</span> andAge<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;2&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>personList addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Person alloc<span style="color: #002200;">&#93;</span> initWithLastName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Bonvoisin&quot;</span> andFirstname<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Bernie&quot;</span> andSex<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Homme&quot;</span> andAge<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;55&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>personList addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Person alloc<span style="color: #002200;">&#93;</span> initWithLastName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Jobs&quot;</span> andFirstname<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Steeve&quot;</span> andSex<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Homme&quot;</span> andAge<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;80&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>personList addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Person alloc<span style="color: #002200;">&#93;</span> initWithLastName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Damien&quot;</span> andFirstname<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Francois&quot;</span> andSex<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Humoriste&quot;</span> andAge<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;35&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>personList addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Person alloc<span style="color: #002200;">&#93;</span> initWithLastName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Gates&quot;</span> andFirstname<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Bill&quot;</span> andSex<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Homme&quot;</span> andAge<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;50&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>personList addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Person alloc<span style="color: #002200;">&#93;</span> initWithLastName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Laporte&quot;</span> andFirstname<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Bernard&quot;</span> andSex<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Rugbyman&quot;</span> andAge<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;32&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>personList addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Person alloc<span style="color: #002200;">&#93;</span> initWithLastName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Chabal&quot;</span> andFirstname<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Sebastien&quot;</span> andSex<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Mythe&quot;</span> andAge<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;36&quot;</span><span style="color: #002200;">&#93;</span><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> populatePersonListAlphabeticalDictionary <span style="color: #002200;">&#123;</span>
	personListAlphabeticalDictionary <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/"><span style="color: #400080;">NSMutableDictionary</span></a> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span>Person <span style="color: #002200;">*</span>currentPerson <span style="color: #a61390;">in</span> personList<span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
&nbsp;
		<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>firstLetter <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>currentPerson.lastname substringToIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
		<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/"><span style="color: #400080;">NSMutableArray</span></a> <span style="color: #002200;">*</span>existingArray;		
		<span style="color: #11740a; font-style: italic;">/* Si on a déjà un array de Person pour cette première lettre*/</span>
		<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>existingArray <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>personListAlphabeticalDictionary valueForKey<span style="color: #002200;">:</span>firstLetter<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> 
		<span style="color: #002200;">&#123;</span>
			<span style="color: #11740a; font-style: italic;">/* On y ajoute la Person en cours*/</span>
			<span style="color: #002200;">&#91;</span>existingArray addObject<span style="color: #002200;">:</span>currentPerson<span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#125;</span>
		<span style="color: #a61390;">else</span>	<span style="color: #11740a; font-style: italic;">/*Sinon, on créée l'array, on y ajoute la Person courante et on ajoute l'array au dictionnaire*/</span>
		<span style="color: #002200;">&#123;</span>
			<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/"><span style="color: #400080;">NSMutableArray</span></a> <span style="color: #002200;">*</span>tempArray <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/"><span style="color: #400080;">NSMutableArray</span></a> array<span style="color: #002200;">&#93;</span>;
			<span style="color: #002200;">&#91;</span>tempArray addObject<span style="color: #002200;">:</span>currentPerson<span style="color: #002200;">&#93;</span>;
			<span style="color: #002200;">&#91;</span>personListAlphabeticalDictionary setObject<span style="color: #002200;">:</span>tempArray forKey<span style="color: #002200;">:</span>firstLetter<span style="color: #002200;">&#93;</span>;			
		<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #11740a; font-style: italic;">/* On génère personNameIndexArray et on trie chaque array de personListAlphabeticalDictionary*/</span>
	<span style="color: #002200;">&#91;</span>self sortPersonInitialLetterIndexes<span style="color: #002200;">&#93;</span>;
&nbsp;
<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> sortPersonInitialLetterIndexes <span style="color: #002200;">&#123;</span>
	personNameIndexArray <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/"><span style="color: #400080;">NSMutableArray</span></a> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	<span style="color: #11740a; font-style: italic;">/* On récupère toutes les premières lettres et on les trie en ignorant la case*/</span>
	personNameIndexArray <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>personListAlphabeticalDictionary allKeys<span style="color: #002200;">&#93;</span> sortedArrayUsingSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>localizedCaseInsensitiveCompare<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span> eachNameIndex <span style="color: #a61390;">in</span> personNameIndexArray<span style="color: #002200;">&#41;</span> 
	<span style="color: #002200;">&#123;</span>
		<span style="color: #002200;">&#91;</span>self presortPersonListAlphabeticalDictionaryForInitialLetter<span style="color: #002200;">:</span>eachNameIndex<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
<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>presortPersonListAlphabeticalDictionaryForInitialLetter<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>aKey <span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">/* Pour chaque array à la clef aKey dans le dictionnaire, on trie le contenu de l'array alphabétiquement sur la propriété lastname en ignorant la case*/</span>
	<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSSortDescriptor_Class/"><span style="color: #400080;">NSSortDescriptor</span></a> <span style="color: #002200;">*</span>nameDescriptor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSSortDescriptor_Class/"><span style="color: #400080;">NSSortDescriptor</span></a> alloc<span style="color: #002200;">&#93;</span> initWithKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;lastname&quot;</span>
																   ascending<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span>
																	selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>localizedCaseInsensitiveCompare<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;	
	<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/"><span style="color: #400080;">NSArray</span></a> <span style="color: #002200;">*</span>descriptors <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/"><span style="color: #400080;">NSArray</span></a> arrayWithObject<span style="color: #002200;">:</span>nameDescriptor<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>personListAlphabeticalDictionary objectForKey<span style="color: #002200;">:</span>aKey<span style="color: #002200;">&#93;</span> sortUsingDescriptors<span style="color: #002200;">:</span>descriptors<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>nameDescriptor release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>Person <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> personForIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSIndexPath_Class/"><span style="color: #400080;">NSIndexPath</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>	
	<span style="color: #11740a; font-style: italic;">/* On récupère la lettre qui a un ID correspondant à la section de l'indexPath */</span>
	<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/"><span style="color: #400080;">NSArray</span></a> <span style="color: #002200;">*</span>personsWithInitLetter <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self personsWithInitialLetter<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>personNameIndexArray objectAtIndex<span style="color: #002200;">:</span>indexPath.section<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #11740a; font-style: italic;">/* Et on renvoie la Person correspondant au row*/</span>
	<span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>personsWithInitLetter objectAtIndex<span style="color: #002200;">:</span>indexPath.row<span style="color: #002200;">&#93;</span>;	
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/"><span style="color: #400080;">NSArray</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>personsWithInitialLetter<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>aKey <span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">/* On renvoie la liste des Person ayant pour première lettre aKey*/</span>
	<span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>personListAlphabeticalDictionary objectForKey<span style="color: #002200;">:</span>aKey<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Maintenant que notre source de données est prête, il n&#8217;y a plus qu&#8217;à mettre en place la TableView en elle-même. La première chose est d&#8217;ajouter un <code>personDataSource</code> comme variable d&#8217;instance et de l&#8217;initialiser (via <code>[[PersonDataSource alloc]init];</code>). Ensuite, on attaque le <code><br />
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath</code>. Le fonctionement est traditionnel. La seule subtilité, c&#8217;est qu&#8217;on va récupérer l&#8217;objet <code>Person</code> via <code>[personDataSource personForIndexPath:indexPath]</code>. </p>
<p>Pour le nombre de sections dans la table, c&#8217;est simple: il y en aura autant que de première lettres. Donc, c&#8217;est tout naturellement que <code>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView</code> renvera [[personDataSource personNameIndexArray] count]</code>. Pour le nombre de lignes dans chaque section, c'est le nombre de <code>Person</code> ayant pour première lettre celle qui correspond à la section courante. C'est pourquoi <code><br />
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section</code> retourne <code>return [[self miniContactsWithInitialLetter:[miniContactNameIndexArray  objectAtIndex:section]] count];</code>. On obtient donc ce code pour le <code>UITableViewController</code>:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p237code58'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p23758"><td class="code" id="p237code58"><pre class="objc" style="font-family:monospace;">&nbsp;
<span style="color: #a61390;">@implementation</span> AlphaTableViewController
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>initWithStyle<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableViewStyle<span style="color: #002200;">&#41;</span>style<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super initWithStyle<span style="color: #002200;">:</span>style<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> 
	<span style="color: #002200;">&#123;</span>
		personDataSource <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>PersonDataSource alloc<span style="color: #002200;">&#93;</span>init<span style="color: #002200;">&#93;</span>;			
		self.tableView.rowHeight <span style="color: #002200;">=</span> <span style="color: #2400d9;">125</span>;		
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>UITableViewCell <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView cellForRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSIndexPath_Class/"><span style="color: #400080;">NSIndexPath</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>
&nbsp;
	<span style="color: #a61390;">static</span> <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>CellIdentifier <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MyCellIdent&quot;</span>;
&nbsp;
    TableCell <span style="color: #002200;">*</span>cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>TableCell <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#91;</span>tableView dequeueReusableCellWithIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>cell <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    	UIViewController <span style="color: #002200;">*</span>c <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIViewController alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;TableViewCell&quot;</span>  bundle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
		cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>TableCell <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>c.view;
		<span style="color: #002200;">&#91;</span>c release<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
	Person <span style="color: #002200;">*</span>currentPerson <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>personDataSource personForIndexPath<span style="color: #002200;">:</span>indexPath<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>cell.firstname setText<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>currentPerson firstname<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>cell.lastname setText<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>currentPerson lastname<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>cell.sex setText<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>currentPerson sex<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;	
	<span style="color: #002200;">&#91;</span>cell.age setText<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>currentPerson age<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;	
&nbsp;
    <span style="color: #a61390;">return</span> cell;
<span style="color: #002200;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>numberOfSectionsInTableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>personDataSource personNameIndexArray<span style="color: #002200;">&#93;</span> count<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView numberOfRowsInSection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>section <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>personDataSource personsWithInitialLetter<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>personDataSource personNameIndexArray<span style="color: #002200;">&#93;</span> objectAtIndex<span style="color: #002200;">:</span>section<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span> count<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Cela donne le résultat ci-dessous. C'est bien, mais il manque encore la liste des lettres sur la droite. C'est pas compliqué <img src='http://webd.fr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .<br />
<a href="http://webd.fr/wp-content/uploads/2009/01/alphabeticaltableviewmiddlescreen.png" rel="lightbox[237]" title="alphabeticaltableviewmiddlescreen"><img src="http://webd.fr/wp-content/uploads/2009/01/alphabeticaltableviewmiddlescreen-161x300.png" alt="alphabeticaltableviewmiddlescreen" title="alphabeticaltableviewmiddlescreen" width="161" height="300" class="aligncenter size-medium wp-image-275" /></a></p>
<p>En fait, il faut être capable de répondre à deux questions posées à l'<code>UITableViewController</code>: <cite>quels sont les titres à afficher pour l'index de la TableView</cite> via <code><br />
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView</code> et <cite>Pour la section X, où faut-il scroller la TableView</cite> via<br />
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index</code>. Au final, il est très facile de répondre à ces questions dans l'architecture que l'on a mis en place. Voilà ce que ça donne dans le code:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p237code59'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p23759"><td class="code" id="p237code59"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/"><span style="color: #400080;">NSArray</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>sectionIndexTitlesForTableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>personDataSource personNameIndexArray<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView sectionForSectionIndexTitle<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>title atIndex<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>index <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> index;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Et le résultat final ... Vous l'avez déjà vu plus haut. Si vous voulez, vous trouverez <a href='http://webd.fr/wp-content/uploads/2009/01/alphatable.zip'>ici une archive du projet complet (Xcode 3.1)</a>.<br />
<!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/237-une-uitableview-triee-par-ordre-alphabetique/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Créer une UITableViewCell personnalisée à partir d’Interface Builder: exemple complet</title>
		<link>http://webd.fr/224-creer-uitableviewcell-personnalisee-interface-builder-exemple</link>
		<comments>http://webd.fr/224-creer-uitableviewcell-personnalisee-interface-builder-exemple#comments</comments>
		<pubDate>Fri, 09 Jan 2009 22:51:47 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=224</guid>
		<description><![CDATA[Il y a peu, j&#8217;exposais ma solution pour Créer une UITableViewCell personnalisée à partir d&#8217;Interface Builder. Suite au commentaire de Bruno Da Silva, je vous laisse une version complètement fonctionnelle de l&#8217;implémentation de cette méthode. Il s&#8217;agit d&#8217;une TableView qui &#8230; <a href="http://webd.fr/224-creer-uitableviewcell-personnalisee-interface-builder-exemple">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Il y a peu, j&#8217;exposais ma solution pour <cite><a href="http://webd.fr/141-creer-une-uitableviewcell-personnalisee-a-partir-dinterface-builder">Créer une UITableViewCell personnalisée à partir d&#8217;Interface Builder</a></cite>. Suite au <a href="http://webd.fr/141-creer-une-uitableviewcell-personnalisee-a-partir-dinterface-builder#comment-86">commentaire de Bruno Da Silva</a>, je vous laisse une version complètement fonctionnelle de l&#8217;implémentation de cette méthode. </p>
<p>Il s&#8217;agit d&#8217;une TableView qui va chercher les dernières photos Flickr avec pour tag « <cite>xmas</cite> ». Pourquoi donner un exemple aussi compliqué ? Tout simplement parce que je n&#8217;ai <b>vraiment</b> pas le temps de faire un exemple complet en ce moment et je voulais publier un exemple rapidement. J&#8217;ai donc récupéré rapidement un exemple de code que j&#8217;ai fais en interne pour le boulot. </p>
<p>La partie de code qui va chercher les images sur FlickR n&#8217;est pas de moi. L&#8217;auteur n&#8217;ayant pas laissé d&#8217;informations le concernant dans le code, je ne pourrais plus vous dire qui c&#8217;est (et ça me désole vraiment). </p>
<p>Voici l&#8217;archive contenant le projet Xcode complet (toute l&#8217;intelligence concernant la méthode pour l&#8217;<code>UITableViewCell</code> se trouve dans <code>MyTableViewController.m</code> à la méthode <code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath</code>): télécharger <a href='http://webd.fr/wp-content/uploads/2009/01/mytableviewdemo.zip'>MyTableViewDemo.zip</a>.<br />
<!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/224-creer-uitableviewcell-personnalisee-interface-builder-exemple/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Réduire la hauteur d&#8217;une UITableView</title>
		<link>http://webd.fr/158-reduire-la-hauteur-dune-uitableview</link>
		<comments>http://webd.fr/158-reduire-la-hauteur-dune-uitableview#comments</comments>
		<pubDate>Mon, 05 Jan 2009 08:23:33 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Pro]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=158</guid>
		<description><![CDATA[Prenons un cas simple: on a une UIView qui contient une simple UITableView (avec le UITableViewController qui va bien) ainsi qu&#8217;une UIToolBar en bas. On se retrouve avec un léger problème: la UITableView ne se redimensionne pas automatiquement en hauteur. &#8230; <a href="http://webd.fr/158-reduire-la-hauteur-dune-uitableview">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Prenons un cas simple: on a une <code>UIView</code> qui contient une simple <code>UITableView</code> (avec le <code>UITableViewController</code> qui va bien) ainsi qu&#8217;une <code>UIToolBar</code> en bas. On se retrouve avec un léger problème: la <code>UITableView</code> ne se redimensionne pas automatiquement en hauteur. Ainsi, les derniers éléments se retrouvent « cachés » par la barre. Voici un exemple fait à la va-vite avec Interface Builder (la <code>UIToolBar</code> a été volontairement mise en transparence pour illustrer le problème):</p>
<p><a href="http://webd.fr/wp-content/uploads/2008/12/uitableviewsizeproblem.png" rel="lightbox[158]" title="uitableviewsizeproblem"><img class="aligncenter size-medium wp-image-159" title="uitableviewsizeproblem" src="http://webd.fr/wp-content/uploads/2008/12/uitableviewsizeproblem-206x299.png" alt="uitableviewsizeproblem" width="206" height="299" /></a></p>
<p>Le souci, c&#8217;est qu&#8217;il n&#8217;est pas possible de préciser dans le code la taille d&#8217;une <code>UITableView</code>. Après avoir essayé plusieurs solutions (dont certaines était plutôt farfelue), j&#8217;en ai retenu une. C&#8217;est celle qui m&#8217;a semblé la plus propre, simple et efficace.<br />
<span id="more-158"></span><br />
Il s&#8217;agit tout simplement de créer une vue vide de la taille de la <code>UIToolBar</code> (par défaut: 44 pixels). Puis de la mettre en tant que <code>tableFooterView</code> (une vue qui n&#8217;est affichée que tout en bas de la <code>UITableView</code>) sur la <code>UITableView</code> courante. L&#8217;idéal c&#8217;est de faire ça directement dans la phase d&#8217;initialisation (dans le <code>UITableViewController</code>). Concrètement ça donne ça:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p158code61'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p15861"><td class="code" id="p158code61"><pre class="objc" style="font-family:monospace;">self.tableView.tableFooterView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">320</span>, <span style="color: #2400d9;">44</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p><!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/158-reduire-la-hauteur-dune-uitableview/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Créer une UITableViewCell personnalisée à partir d&#8217;Interface Builder</title>
		<link>http://webd.fr/141-creer-une-uitableviewcell-personnalisee-a-partir-dinterface-builder</link>
		<comments>http://webd.fr/141-creer-une-uitableviewcell-personnalisee-a-partir-dinterface-builder#comments</comments>
		<pubDate>Fri, 26 Dec 2008 09:21:35 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Pro]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=141</guid>
		<description><![CDATA[Le problème La TableView est un composant essentiel de l&#8217;HIM de l&#8217;iPhone très simple à développer pour des besoins simples. Clairement, si on doit afficher à l&#8217;utilisateur des cellules avec une seule ligne de texte, ça se fait les doigts &#8230; <a href="http://webd.fr/141-creer-une-uitableviewcell-personnalisee-a-partir-dinterface-builder">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h1>Le problème</h1>
<p>La TableView est un composant essentiel de l&#8217;HIM de l&#8217;iPhone très simple à développer pour des besoins simples. Clairement, si on doit afficher à l&#8217;utilisateur des cellules avec une seule ligne de texte, ça se fait les doigts dans le nez.</p>
<p>Là où les choses se corsent, c&#8217;est quand il faut créer des cellules personnalisées. Avec, par exemple, deux <code>UILabel</code> et une <code>UIImageView</code>. En effet, il n&#8217;existe pas de méthode pour charger un nib (comme l&#8217;habituel <code>initWithNibName:</code>). Ainsi, on se retrouve forcé à créer tout nos éléments et à les placer à la main dans le code. C&#8217;est loin d&#8217;être quelque chose d&#8217;agréable, simple et rapide à faire. Sans compter qu&#8217;au moindre changement de design de la cellule, on perd un temps fou.</p>
<h1>La solution</h1>
<p>Non, l&#8217;idéal c&#8217;est de pouvoir utiliser Interface Builder pour construire ses cellules&#8230; Après quelques essais, recherches et erreurs, voici la solution que j&#8217;ai trouvé (et que j&#8217;utilise):</p>
<p><span id="more-141"></span></p>
<p>On commence par créer une nouvelle interface dans IB. On y ajoute une TableCell (au passage, le nib ne doit contenir que des TableCell&#8217;s !). Dans la TableCell, on ajoute les éléments dont on a besoin (ici, deux <code>UILabel</code> et un <code>UIImageView</code>). On définit la <cite>Class Identity</cite> et les <cite>Class Outlets</cite> qui vont bien. On finit par un <cite>Write Classfile</cite> et on a notre nib et l&#8217;<code>UITableViewCell</code> dans le projet.<br />
<a href="http://webd.fr/wp-content/uploads/2008/12/tableviewcellxibscreen.jpg" rel="lightbox[141]" title="tableviewcellxibscreen"><img src="http://webd.fr/wp-content/uploads/2008/12/tableviewcellxibscreen-300x233.jpg" alt="tableviewcellxibscreen" title="tableviewcellxibscreen" width="300" height="233" class="aligncenter size-medium wp-image-150" /></a></p>
<p>Maintenant, il faut s&#8217;occuper de l&#8217;<code>UITableViewController</code>. L&#8217;utilisation d&#8217;un nib ne change absolument rien au fonctionnement habituel. Ce n&#8217;est qu&#8217;à la création de la cellule (dans <code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath</code>) que cela change un peu. Voilà ce que ça donne:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p141code63'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14163"><td class="code" id="p141code63"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#40;</span>UITableViewCell <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView cellForRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSIndexPath_Class/"><span style="color: #400080;">NSIndexPath</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">static</span> <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>CellIdentifier <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MyCellIdent&quot;</span>;
    MyTableViewCell <span style="color: #002200;">*</span>cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>MyTableViewCell <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#91;</span>tableView dequeueReusableCellWithIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>cell <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    	<span style="color: #11740a; font-style: italic;">// On initialise un ViewController à partir du Nib qui a été fait</span>
    	UIViewController <span style="color: #002200;">*</span>c <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIViewController alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MyTableViewCell&quot;</span>  bundle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #11740a; font-style: italic;">// On récupère sa vue et on la caste dans le type de notre TableViewCell</span>
	cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>MyTableViewCell <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>c.view;
	<span style="color: #002200;">&#91;</span>c release<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #11740a; font-style: italic;">// Ensuite, ça reste traditionnel</span>
    cell.label1.text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>myObjects objectAtIndex<span style="color: #002200;">:</span>indexPath.row<span style="color: #002200;">&#93;</span> name<span style="color: #002200;">&#93;</span>;
    cell.label2.text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>myObjects objectAtIndex<span style="color: #002200;">:</span>indexPath.row<span style="color: #002200;">&#93;</span> desc<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>cell.uIImageView  setImage<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>myObjects objectAtIndex<span style="color: #002200;">:</span>indexPath.row<span style="color: #002200;">&#93;</span> image<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">return</span> cell;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Les développeurs avisés auront très certainement remarqué un petit détail qui a son importance: on ne définit jamais (lors de la création de la cellule) son <code>CellIdentifier</code>, ainsi la réutilisation de cellules devient impossible (ce qui est suicidaire en terme de mémoire). En fait, celui-ci se définit dans Interface Builder. Dans les propriétés de votre TableViewCell, il suffit de mettre votre <code>CellIndetifier</code> dans <cite>Identifier</cite>. Ici, on mettra donc <cite> MyCellIdent</cite>.</p>
<p>Vous voilà maintenant avec des TableViewCell générée à partir d&#8217;Interface Builder en gardant possible le mécanisme de ré-utilisation de cellules. Ça, c&#8217;est des demies journées de gagnées sur vos projets (si ils comportent des cellules personnalisées bien évidement).</p>
<p><strong>Édition du 09/01/09:</strong><br />
Un exemple de code complet et opérationnel est disponible dans le billet <cite><a href="http://webd.fr/224-creer-uitableviewcell-personnalisee-interface-builder-exemple">Créer une UITableViewCell personnalisée à partir d’Interface Builder: exemple complet</a></cite><br />
<!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/141-creer-une-uitableviewcell-personnalisee-a-partir-dinterface-builder/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Afficher l&#8217;image d&#8217;un contact de l&#8217;AddressBook de l’iPhone</title>
		<link>http://webd.fr/128-image-contact-addressbook-iphone</link>
		<comments>http://webd.fr/128-image-contact-addressbook-iphone#comments</comments>
		<pubDate>Sat, 20 Dec 2008 10:43:56 +0000</pubDate>
		<dc:creator>Julien Quéré</dc:creator>
				<category><![CDATA[Pro]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[Developpement]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://webd.fr/?p=128</guid>
		<description><![CDATA[Il y a peu, je parlais de la sérialisation d&#8217;un contact dans l&#8217;AddressBook de l&#8217;iPhone. Toujours dans la même veine, voyons comment afficher, dans une application, la photographie d&#8217;un contact de l&#8217;AddressBook. L&#8217;idée est de partir du ABRecordRef correspondant au &#8230; <a href="http://webd.fr/128-image-contact-addressbook-iphone">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Il y a peu, je parlais de la <a href="http://webd.fr/120-serialiser-identifiant-contact-iphone">sérialisation d&#8217;un contact dans l&#8217;AddressBook de l&#8217;iPhone</a>. Toujours dans la même veine, voyons comment afficher, dans une application, la photographie d&#8217;un contact de l&#8217;AddressBook. </p>
<p>L&#8217;idée est de partir du <code>ABRecordRef</code> correspondant au contact dont on souhaite afficher l&#8217;image. A partir de là, on vérifie que ce contact dispose bien d&#8217;une photo dans sa fiche (via <code>ABPersonHasImageData()</code>. Pour finir, on récupère les données brutes de l&#8217;image (<code> ABPersonCopyImageData()</code>) et on crée la <code>UIImage</code> qui va bien (via <code>initWithData:</code>). </p>
<p>Au final, voilà ce que ça donne: </p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p128code65'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12865"><td class="code" id="p128code65"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>ABPersonHasImageData<span style="color: #002200;">&#40;</span>recordRef<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
	<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/"><span style="color: #400080;">NSData</span></a> <span style="color: #002200;">*</span>myAvatarData <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/"><span style="color: #400080;">NSData</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> ABPersonCopyImageData<span style="color: #002200;">&#40;</span>recordRef<span style="color: #002200;">&#41;</span>;
	UIImage <span style="color: #002200;">*</span>avatarImage <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImage alloc<span style="color: #002200;">&#93;</span> initWithData<span style="color: #002200;">:</span>myAvatarData<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>myAvatarData release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Après, il ne faut pas oublier de libérer <code>myAvatarData</code> puisqu&#8217;il est devenu inutile. Charge à vous ensuite d&#8217;afficher <code>avatarImage</code> dans le <code>UIImageView</code> qui va bien. Simple non ?</p>
<p><!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://webd.fr/128-image-contact-addressbook-iphone/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

