<?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>FruityFred &#187; Cocoa</title>
	<atom:link href="http://www.fruityfred.com/category/dev/cocoa-mac/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fruityfred.com</link>
	<description>Blog d&#039;un développeur (web &#38;&#38; Mac) qui aime bouger et la bonne cuisine</description>
	<lastBuildDate>Wed, 04 Jan 2012 20:58:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Révision des MacBook : je vends mes Mac !</title>
		<link>http://www.fruityfred.com/2009/06/08/revision-des-macbook/</link>
		<comments>http://www.fruityfred.com/2009/06/08/revision-des-macbook/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 21:22:05 +0000</pubDate>
		<dc:creator>Fred</dc:creator>
				<category><![CDATA[Annonces]]></category>
		<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.glimpse-fr.org/?p=793</guid>
		<description><![CDATA[Les MacBook ont également été revus aujourd&#8217;hui : plus de puissance, lecteur de cartes SD (oui je sais, toute la concurrence le fait déjà !) et baisse des prix. Dans quelques semaines, je devrais avoir mon nouveau MacBook pro. Et je souhaite n&#8217;avoir plus qu&#8217;une seule machine. Je vais donc revendre mon iMac 20 pouces [...]]]></description>
			<content:encoded><![CDATA[<p>Les <a href="http://www.apple.com/fr/macbook/" xml:lang="en" hreflang="fr" onclick="pageTracker._trackPageview('/outgoing/www.apple.com/fr/macbook/?referer=');">MacBook</a> ont également été revus aujourd&#8217;hui : plus de puissance, lecteur de cartes SD (oui je sais, toute la concurrence le fait déjà !) et baisse des prix. Dans quelques semaines, je devrais avoir mon nouveau <a href="http://www.apple.com/fr/macbook/" xml:lang="en" hreflang="fr" onclick="pageTracker._trackPageview('/outgoing/www.apple.com/fr/macbook/?referer=');">MacBook</a> pro. Et je souhaite n&#8217;avoir plus qu&#8217;une seule machine.</p>
<p><strong>Je vais donc revendre mon <a href="http://www.apple.com/fr/imac/" xml:lang="en" hreflang="fr" onclick="pageTracker._trackPageview('/outgoing/www.apple.com/fr/imac/?referer=');">iMac</a> 20 pouces (que pourtant j&#8217;adooore) ainsi que mon <a href="http://www.apple.com/fr/macbook/" xml:lang="en" hreflang="fr" onclick="pageTracker._trackPageview('/outgoing/www.apple.com/fr/macbook/?referer=');">MacBook</a> 13 pouces noir.</strong></p>
<p>Mon <a href="http://www.apple.com/fr/imac/" xml:lang="en" hreflang="fr" onclick="pageTracker._trackPageview('/outgoing/www.apple.com/fr/imac/?referer=');">iMac</a> est <strong>disponible immédiatement</strong> pour <a href="http://www.mac2sell.net/permalink/?id=4596c51af5758d13e513a7d5337ad0bb" onclick="pageTracker._trackPageview('/outgoing/www.mac2sell.net/permalink/?id=4596c51af5758d13e513a7d5337ad0bb&amp;referer=');">environ 830 euros</a>. Le <a href="http://www.apple.com/fr/macbook/" xml:lang="en" hreflang="fr" onclick="pageTracker._trackPageview('/outgoing/www.apple.com/fr/macbook/?referer=');">MacBook</a> sera disponible quand j&#8217;aurai le nouveau et terminé la migration (dans l&#8217;été, donc) pour <a href="http://www.mac2sell.net/permalink/?id=d6e6fe386233f269f20856cbb1938345" onclick="pageTracker._trackPageview('/outgoing/www.mac2sell.net/permalink/?id=d6e6fe386233f269f20856cbb1938345&amp;referer=');">environ 800 euros</a>. Ces deux (superbes) machines seront entièrement ré-installées proprement avec la dernière version de <span class="nobr"><a href="http://www.apple.com/fr/macosx/" hreflang="fr" onclick="pageTracker._trackPageview('/outgoing/www.apple.com/fr/macosx/?referer=');">Mac OS X</a></span> et livrées dans leur boîte d&#8217;origine, avec tous les accessoires (télécommande, chiffon de nettoyage et <abbr title="Digital Versatile Disc" xml:lang="en">DVD</abbr> de <span class="nobr"><a href="http://www.apple.com/fr/macosx/" hreflang="fr" onclick="pageTracker._trackPageview('/outgoing/www.apple.com/fr/macosx/?referer=');">Mac OS X</a></span>).</p>
<p>Si vous êtes intéressés, ou si vous connaissez des personnes qui pourraient être intéressées, n&#8217;hésitez pas à <a href="http://www.glimpse-fr.org/apropos/contact/" onclick="pageTracker._trackPageview('/outgoing/www.glimpse-fr.org/apropos/contact/?referer=');">prendre contact avec moi</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fruityfred.com/2009/06/08/revision-des-macbook/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Une liste déroulante qui se souvient et qui propose</title>
		<link>http://www.fruityfred.com/2009/03/06/une-liste-deroulante-qui-se-souvient-et-qui-propose/</link>
		<comments>http://www.fruityfred.com/2009/03/06/une-liste-deroulante-qui-se-souvient-et-qui-propose/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 18:28:34 +0000</pubDate>
		<dc:creator>Fred</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Développement]]></category>
		<category><![CDATA[Tutoriels]]></category>
		<category><![CDATA[auto-complétion]]></category>
		<category><![CDATA[datasource]]></category>
		<category><![CDATA[liste déroulante]]></category>
		<category><![CDATA[NSComboBox]]></category>
		<category><![CDATA[User Defaults]]></category>

		<guid isPermaLink="false">http://www.glimpse-fr.org/?p=680</guid>
		<description><![CDATA[Le but de cet article est de nous familiariser avec le widget NSComboBox. Il existe deux manières de peupler une liste déroulante : à la main dans Interface Builder, ou via l&#8217;utilisation d&#8217;une source de données. Nous allons ici nous intéresser à la seconde : l&#8217;utilisation d&#8217;une datasource. Cet article parle de notions présentées dans [...]]]></description>
			<content:encoded><![CDATA[<p>Le but de cet article est de nous familiariser avec le widget <a href="http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSComboBox_Class/index.html" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSComboBox_Class/index.html?referer=');"><code>NSComboBox</code></a>. Il existe deux manières de peupler une liste déroulante : à la main dans <span xml:lang="en">Interface Builder</span>, ou <em>via</em> l&#8217;utilisation d&#8217;une source de données. Nous allons ici nous intéresser à la seconde : l&#8217;utilisation d&#8217;une <span title="source de données" xml:lang="en">datasource</span>.</p>
<p>Cet article parle de notions présentées dans ce <a href="http://www.glimpse-fr.org/developpement/xcode-interfacebuilder/" onclick="pageTracker._trackPageview('/outgoing/www.glimpse-fr.org/developpement/xcode-interfacebuilder/?referer=');">tutoriel pour <span xml:lang="en">Xcode</span> et <span xml:lang="en">Interface Builder</span></a>. N&#8217;hésitez pas à aller vous rafraîchir la mémoire !</p>
<p>Dans <span xml:lang="en">Interface Builder</span>, ajoutons une <em>Combo Box</em> dans notre vue puis, dans le premier onglet de l&#8217;inspecteur, cochons&#8230; tiens, il est marrant ce verbe conjugué au présent à la première personne du pluriel ! Hum. Cochons, donc, la case <em title="Utilise une source de données" xml:lang="en">Uses Data Source</em>.</p>
<p><strong>La datasource est un objet de votre choix</strong> qui contient les données à afficher dans la liste déroulante. Cet objet <strong>retrouve et stocke les données sous la forme qu&#8217;il souhaite</strong>. Généralement, on a souvent affaire à un <a href="http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSArray_Class/Reference/Reference.html" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSArray_Class/Reference/Reference.html?referer=');"><code>NSArray</code></a> qui pourrait être lu depuis un fichier <abbr title="Properties List" xml:lang="en">plist</abbr>&#8230; ou depuis les <a xml:lang="en" href="http://developer.apple.com/documentation/Cocoa/Conceptual/UserDefaults/UserDefaults.html" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/documentation/Cocoa/Conceptual/UserDefaults/UserDefaults.html?referer=');"><em title="base de données des préférences de l'utilisateur" xml:lang="en">User Defaults</em></a>. Bref, la seule contrainte est que cet objet doit <strong>implémenter le protocole informel <a href="http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Protocols/NSComboBoxDataSource_Protocol/Reference/Reference.html" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Protocols/NSComboBoxDataSource_Protocol/Reference/Reference.html?referer=');"><code>NSComboBoxDataSource</code></a></strong> :</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>numberOfItemsInComboBox<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSComboBox</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>combo;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>comboBox<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSComboBox</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>combo objectValueForItemAtIndex<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>index</pre></div></div>

<p>La première méthode doit retourner <strong>le nombre d&#8217;éléments</strong> qui devront être présents dans la liste déroulante. La seconde retourne <strong>l&#8217;objet pour un index donné</strong> (le message <code>description</code> sera envoyé à cet objet pour l&#8217;affichage dans la liste déroulante). Remarquez que ces méthodes acceptent toutes les deux une <code>NSComboBox</code> en argument. Ceci permet de n&#8217;utiliser qu&#8217;une seule classe pour gérer plusieurs sources de données : en fonction de l&#8217;objet <code>combo</code> passé en argument, il est facile de déterminer les données à utiliser.</p>
<p>Dans notre exemple, considérons que l&#8217;objet datasource est notre contrôleur principal, déclaré dans <span xml:lang="en">Interface Builder</span>. On peut donc utiliser sa méthode <code>awakeFromNib</code> pour initialiser ce qu&#8217;on veut. Ici, on va récupérer des données stockées dans les <em>User Defaults</em> :</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> loadDataSource <span style="color: #002200;">&#123;</span>
   <span style="color: #11740a; font-style: italic;">// On récupère une instance des User Defaults</span>
   <span style="color: #400080;">NSUserDefaults</span> <span style="color: #002200;">*</span>defaults <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSUserDefaults</span> standardUserDefaults<span style="color: #002200;">&#93;</span>;
   <span style="color: #11740a; font-style: italic;">// On lit les valeurs avec la clé qu'on a choisit (ici : ComboBoxValues)</span>
   <span style="color: #11740a; font-style: italic;">// dataSource est un NSArray déclaré dans le fichier header de cette classe</span>
   dataSource <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>defaults arrayForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;ComboBoxValues&quot;</span><span style="color: #002200;">&#93;</span>
                           sortedArrayUsingSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>compare<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
   <span style="color: #11740a; font-style: italic;">// Au passage, on trie les éléments par ordre alphabétique :-)</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>awakeFromNib <span style="color: #002200;">&#123;</span>
   <span style="color: #11740a; font-style: italic;">// On charge nos données depuis les &quot;préférences&quot; de l'utilisateur</span>
   <span style="color: #002200;">&#91;</span>self loadDataSource<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Ensuite, nous allons implémenter les deux fameuses méthodes du protocole <code>NSComboBoxDataSource</code> qui sont, comme vous le constatez, très complexes :</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>numberOfItemsInComboBox<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSComboBox</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>aComboBox <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>dataSource 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><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>comboBox<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSComboBox</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>aComboBox objectValueForItemAtIndex<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>index <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>dataSource objectAtIndex<span style="color: #002200;">:</span>index<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Il nous reste à <strong>indiquer à notre <code>NSCombBox</code> la datasource à utiliser</strong>. Allons dans <span xml:lang="en">Interface Builder</span>, sélectionnons la liste déroulante, activons l&#8217;onglet <em>Connections</em> de l&#8217;inspecteur puis relions l&#8217;entrée <em>dataSource</em> à notre contrôleur.</p>
<p>Très bien, mais il faut encore <strong>ajouter les données saisies dans les <em>User Defaults</em></strong>, sinon l&#8217;entrée <em>ComboBoxValues</em> (voir la méthode <code>loadDataSource</code>) sera toujours un tableau vide&#8230; Et on aurait fait tout ça pour rien ! Il faut d&#8217;abord obtenir une instance de notre liste déroulante dans notre contrôleur via l&#8217;utilisation des <code>IBOutlet</code> (plus d&#8217;informations <a title="Tutoriels Xcode et Interface Builder" href="http://www.glimpse-fr.org/developpement/xcode-interfacebuilder/" onclick="pageTracker._trackPageview('/outgoing/www.glimpse-fr.org/developpement/xcode-interfacebuilder/?referer=');">ici</a>). Ensuite, il faut déterminer le moment où vous l&#8217;on souhaite que la valeur soit sauvegardée : lorsque que l&#8217;utilisateur termine la saisie dans la liste déroulante ou bien lors d&#8217;une autre action (sauvegarde des différents champs d&#8217;un formulaire, par exemple). Dans les deux cas, il faut déclarer une <code>IBAction</code> quelque part (plus d&#8217;informations <a title="Tutoriels Xcode et Interface Builder" href="http://www.glimpse-fr.org/developpement/xcode-interfacebuilder/" onclick="pageTracker._trackPageview('/outgoing/www.glimpse-fr.org/developpement/xcode-interfacebuilder/?referer=');">ici</a>). Dans cette action, il nous faut ajouter un morceau de code qui ressemble à ceci :</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Récupération de la valeur saisie dans la NSComboBox</span>
<span style="color: #11740a; font-style: italic;">// comboBox est un IBOutlet déclaré dans le fichier header (voir plus bas)</span>
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>newValue <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>comboBox stringValue<span style="color: #002200;">&#93;</span>;
<span style="color: #11740a; font-style: italic;">// On vérifie si la valeur n'est pas déjà présente, auquel cas il n'y a</span>
<span style="color: #11740a; font-style: italic;">// rien à faire.</span>
<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#91;</span>taskNameDataSource containsObject<span style="color: #002200;">:</span> newValue<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> <span style="color: #a61390;">NO</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
   <span style="color: #400080;">NSUserDefaults</span> <span style="color: #002200;">*</span>defaults <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSUserDefaults</span> standardUserDefaults<span style="color: #002200;">&#93;</span>;
   <span style="color: #11740a; font-style: italic;">// On va ajouter un élément à notre dataSource :</span>
   <span style="color: #11740a; font-style: italic;">// pour cela, il nous faut un NSMutableArray (NSArray étant en lecture seule)</span>
   <span style="color: #400080;">NSMutableArray</span> <span style="color: #002200;">*</span>mutableDS <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> arrayWithArray<span style="color: #002200;">:</span> dataSource<span style="color: #002200;">&#93;</span>;
   <span style="color: #11740a; font-style: italic;">// On ajoute la nouvelle valeur</span>
   <span style="color: #002200;">&#91;</span>mutableDS addObject<span style="color: #002200;">:</span> newValue<span style="color: #002200;">&#93;</span>;
   <span style="color: #11740a; font-style: italic;">// On stocke le tout dans les User Defaults</span>
   <span style="color: #002200;">&#91;</span>defaults setValue<span style="color: #002200;">:</span> mutableDS forKey<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;ComboBoxValues&quot;</span><span style="color: #002200;">&#93;</span>;
   <span style="color: #11740a; font-style: italic;">// Et on met à jour la liste déroulante pour qu'elle prenne la nouvelle</span>
   <span style="color: #11740a; font-style: italic;">// valeur en compte (il y a peut-être mieux à faire ici).</span>
   <span style="color: #002200;">&#91;</span>self loadDataSource<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Enfin, voici un exemple de fichier header pour notre contrôleur principal :</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> AppController <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> <span style="color: #002200;">&#123;</span>
	IBOutlet <span style="color: #400080;">NSComboBox</span><span style="color: #002200;">*</span> comboBox;
	<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>dataSource;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// Méthodes de gestion de la datasource pour la NSComboBox</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>numberOfItemsInComboBox<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSComboBox</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>aComboBox;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>comboBox<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSComboBox</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>aComboBox objectValueForItemAtIndex<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>index;</pre></div></div>

<p>Une dernière chose : il est possible de voir les préférences d&#8217;une application depuis le <strong>Terminal</strong>, grâce à la commande suivante :</p>
<p><kbd class="console"><br />
 defaults read identifiant.de.votre.application<br />
 </kbd></p>
<p>L&#8217;identifiant de votre application doit être unique et on le définit dans <span xml:lang="en">Xcode</span>, dans les informations de la target : dans l&#8217;arborescence de <span xml:lang="en">Xcode</span>, dans la section <em>Targets</em>, faites un clic droit sur votre target puis <em>Get Info</em> et enfin onglet <em>Properties</em> ; le champ à renseigner est&#8230; Tah daaah : <em>Identifier</em>. Utilisez un nom comme les packages <a href="http://java.com/fr/" onclick="pageTracker._trackPageview('/outgoing/java.com/fr/?referer=');">Java</a> : <em>com.entreprise.application</em>. Attention : les defaults sont généralement synchronisés et enregistrés sur le disque à la fermeture de l&#8217;application (ou avant, mais on ne sait pas quand) : il est donc possible de ne pas les voir tout de suite à jour dans le Terminal.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fruityfred.com/2009/03/06/une-liste-deroulante-qui-se-souvient-et-qui-propose/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Savoir si une application est lancée ou pas</title>
		<link>http://www.fruityfred.com/2009/03/06/savoir-si-une-application-est-lancee-ou-pas/</link>
		<comments>http://www.fruityfred.com/2009/03/06/savoir-si-une-application-est-lancee-ou-pas/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 17:18:24 +0000</pubDate>
		<dc:creator>Fred</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Développement]]></category>
		<category><![CDATA[Tutoriels]]></category>
		<category><![CDATA[NSWorkspace]]></category>

		<guid isPermaLink="false">http://www.glimpse-fr.org/?p=693</guid>
		<description><![CDATA[Pour savoir si une application est lancée ou pas, on peut utiliser les services fournis par la classe NSWorkspace, et notamment sa méthode launchedApplications : - &#40;BOOL&#41; isAppLaunched: &#40;NSString *&#41; appIdentifier &#123; NSArray *apps = &#91;&#91;NSWorkspace sharedWorkspace&#93; launchedApplications&#93;; for &#40;NSDictionary *appInfo in apps&#41; &#123; NSString *appId = &#91;appInfo objectForKey: @&#34;NSApplicationBundleIdentifier&#34;&#93;; if &#40;&#91;appId isEqualTo: appIdentifier&#93;&#41; &#123; [...]]]></description>
			<content:encoded><![CDATA[<p>Pour savoir si une application est lancée ou pas, on peut utiliser les services fournis par la classe <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWorkspace_Class/Reference/Reference.html" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWorkspace_Class/Reference/Reference.html?referer=');"><code>NSWorkspace</code></a>, et notamment sa méthode <code>launchedApplications</code> :</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> isAppLaunched<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> appIdentifier <span style="color: #002200;">&#123;</span>
   <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>apps <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSWorkspace</span> sharedWorkspace<span style="color: #002200;">&#93;</span> launchedApplications<span style="color: #002200;">&#93;</span>;
   <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>appInfo <span style="color: #a61390;">in</span> apps<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
      <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>appId <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>appInfo objectForKey<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;NSApplicationBundleIdentifier&quot;</span><span style="color: #002200;">&#93;</span>;
      <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>appId isEqualTo<span style="color: #002200;">:</span> appIdentifier<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
         <span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>;
      <span style="color: #002200;">&#125;</span>
   <span style="color: #002200;">&#125;</span>
   <span style="color: #a61390;">return</span> <span style="color: #a61390;">NO</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#91;</span>self isAppLaunched<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;com.apple.iCal&quot;</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;iCal est lancé !&quot;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.fruityfred.com/2009/03/06/savoir-si-une-application-est-lancee-ou-pas/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Développer son framework Cocoa</title>
		<link>http://www.fruityfred.com/2009/02/12/developper-son-framework-cocoa/</link>
		<comments>http://www.fruityfred.com/2009/02/12/developper-son-framework-cocoa/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 00:38:09 +0000</pubDate>
		<dc:creator>Fred</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Développement]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Tutoriels]]></category>
		<category><![CDATA[framework]]></category>

		<guid isPermaLink="false">http://www.glimpse-fr.org/?p=643</guid>
		<description><![CDATA[Dans cet article, je vous explique comment créer votre propre framework Cocoa (écrit en Objective-C, donc), afin de réutiliser du code dans plusieurs de vos applications. Le framework en question a pour vocation d&#8217;être inclus dans le bundle de vos applications (on ne va tout de même pas copier des librairies un peu partout !). [...]]]></description>
			<content:encoded><![CDATA[<p>Dans cet article, je vous explique comment créer <strong>votre propre framework <a href="http://fr.wikipedia.org/wiki/Cocoa_(Apple)" xml:lang="en" hreflang="fr" onclick="pageTracker._trackPageview('/outgoing/fr.wikipedia.org/wiki/Cocoa_Apple?referer=');">Cocoa</a></strong> (écrit en Objective-C, donc), afin de réutiliser du code dans plusieurs de vos applications. Le framework en question a pour vocation d&#8217;être <strong>inclus dans le bundle de vos applications</strong> (on ne va tout de même pas copier des librairies un peu partout !). Il y a <strong>deux grandes étapes</strong> :</p>
<ul>
<li>la création du framework,</li>
<li>l&#8217;utilisation du framework dans vos applications.</li>
</ul>
<p><strong>Création du framework</strong></p>
<p><img class="alignleft size-full wp-image-646 no-border" title="Cocoa Framework" src="http://www.fruityfred.com/wp-content/uploads/2009/02/cocoa-framework.png" alt="Cocoa Framework" width="118" height="75" /></p>
<p>Dans <span xml:lang="en">Xcode</span>, choisissez <em>File > New Project&#8230;</em> puis choisissez un projet de type <em>Framework</em> et plus précisément<em> <a href="http://fr.wikipedia.org/wiki/Cocoa_(Apple)" xml:lang="en" hreflang="fr" onclick="pageTracker._trackPageview('/outgoing/fr.wikipedia.org/wiki/Cocoa_Apple?referer=');">Cocoa</a> Framework.</em> Saisissez un joli nom pour votre framework. </p>
<p>Faites un clic droit sur la target de votre framework puis choisissez <em>Set Role > Public</em> : ceci aura pour effet de copier les fichiers headers (.h) dans le framework, ce qui s&#8217;avère très utile pour utiliser ledit framework !</p>
<p><img class="aligncenter size-full wp-image-649 screenshot" title="Framework Set Role Public" src="http://www.fruityfred.com/wp-content/uploads/2009/02/framework-set-role-public.png" alt="Framework Set Role Public" width="325" height="139" /></p>
<p>Éditez maintenant les <strong>propriétés de la target</strong> de votre framework (clic droit sur la target puis <em>Get Info</em>). Dans l&#8217;onglet <em>Build</em>, recherchez la section <em>Deployment</em> puis remplacez la valeur de la propriété <em>Installation Directory</em> par <code>@executable_path/../Frameworks</code>. Vous devriez avoir quelque chose qui ressemble à ceci :</p>
<p><img class="aligncenter size-full wp-image-652 screenshot" title="Framework Build Properties" src="http://www.fruityfred.com/wp-content/uploads/2009/02/framework-build-properties.png" alt="Framework Build Properties" width="566" height="194" /></p>
<p>Ajoutez ensuite toutes les classes et ressources à votre framework puis compilez le framework (<em>Build</em>). Rendez-vous dans le répertoire <em>build</em> de votre projet et vérifiez que vous avez bien un dossier avec l&#8217;extension <em>.framework</em>.</p>
<p><strong>Utilisation du framework dans vos applications</strong></p>
<p>Il y a deux choses importantes à faire ici :</p>
<ul>
<li><strong>ajouter le framework</strong> à votre application (ce qui semble logique&#8230;),</li>
<li>faire en sorte que ce framework se retrouve dans le dossier <em>Frameworks</em> <strong>à l&#8217;intérieur du bundle de votre application</strong> une fois votre application compilée.</li>
</ul>
<p>Pour ajouter le framework à votre application, faites un clic droit sur la section <em>Frameworks</em> dans l&#8217;arborescence du projet puis<em> Add > Existing Frameworks&#8230;</em> puis parcourez votre disque à la recherche de votre framework (qui est un dossier à l&#8217;extension <em>.framework</em>, je vous le rappelle).</p>
<p><img class="aligncenter size-full wp-image-654 screenshot" title="application-add-existing-framework" src="http://www.fruityfred.com/wp-content/uploads/2009/02/application-add-existing-framework.png" alt="application-add-existing-framework" width="467" height="159" /></p>
<p>Pour la deuxième partie, faites un clic droit sur la target de votre application puis <em>Add > New Build Phase > New Copy Files Build Phase</em>.</p>
<p><img class="aligncenter size-full wp-image-656 screenshot" title="Add New Build Phase" src="http://www.fruityfred.com/wp-content/uploads/2009/02/add-new-build-phase.png" alt="Add New Build Phase" width="656" height="76" /></p>
<p>Dans la boîte de dialogue, sélectionnez <em>Frameworks</em> pour le champ <em>Destination</em> et fermez la fenêtre (surtout qu&#8217;il fait froid en ce moment).</p>
<p><img class="aligncenter size-full wp-image-657 screenshot" title="Destination Frameworks" src="http://www.fruityfred.com/wp-content/uploads/2009/02/destination-frameworks.png" alt="Destination Frameworks" width="276" height="29" /></p>
<p>Enfin, dans l&#8217;arborescence du projet, faites glisser votre framework depuis la section <em>Frameworks</em> vers la nouvelle section <em>Copy Files</em> : vous devriez alors le voir apparaître en dessous et le libellé de la phase est maintenant <em>Copy Files (1)</em>.</p>
<p>Dans votre application, vous devrez inclure les fichiers headers de vos classes de cette manière :</p>

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

<p>Voilà, ça devrait marcher&#8230; amusez-vous bien !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fruityfred.com/2009/02/12/developper-son-framework-cocoa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Glisser-déposer de fichiers dans votre application</title>
		<link>http://www.fruityfred.com/2009/01/19/glisser-deposer-de-fichiers-dans-votre-application/</link>
		<comments>http://www.fruityfred.com/2009/01/19/glisser-deposer-de-fichiers-dans-votre-application/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 20:49:01 +0000</pubDate>
		<dc:creator>Fred</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Développement]]></category>
		<category><![CDATA[Tutoriels]]></category>
		<category><![CDATA[drag and drop]]></category>
		<category><![CDATA[NSView]]></category>

		<guid isPermaLink="false">http://www.glimpse-fr.org/?p=596</guid>
		<description><![CDATA[Dans cet article, je vais vous montrer comment on peut très simplement gérer le drag and drop de fichiers depuis le Finder vers votre application. Il faut créer une sous-classe de NSView, par exemple DropFilesView. Dans cette classe, il faut indiquer à Cocoa que cette vue accepte la dépose de fichiers par drag and drop. [...]]]></description>
			<content:encoded><![CDATA[<p>Dans cet article, je vais vous montrer comment on peut très simplement gérer le <span title="glisser/déposer" xml:lang="en">drag and drop</span> de fichiers depuis le Finder vers votre application.</p>
<p>Il faut créer une sous-classe de <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/nsview_Class/Reference/NSView.html" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/nsview_Class/Reference/NSView.html?referer=');"><code>NSView</code></a>, par exemple <code>DropFilesView</code>. Dans cette classe, il faut indiquer à <a href="http://fr.wikipedia.org/wiki/Cocoa_(Apple)" xml:lang="en" hreflang="fr" onclick="pageTracker._trackPageview('/outgoing/fr.wikipedia.org/wiki/Cocoa_Apple?referer=');">Cocoa</a> que cette vue <strong>accepte la dépose de fichiers par drag and drop</strong>. Pour cela, on implémente la méthode <code>-awakeFromNib</code> comme ceci :</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> awakeFromNib <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>self registerForDraggedTypes<span style="color: #002200;">:</span>
     <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> arrayWithObjects<span style="color: #002200;">:</span> NSFilenamesPboardType, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>
    <span style="color: #002200;">&#93;</span>;
    <span style="color: #11740a; font-style: italic;">// Attention à ne pas oublier le &quot;nil&quot; en dernier argument de</span>
    <span style="color: #11740a; font-style: italic;">// arrayWithObjects !</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Je vous rappelle que la méthode <code>-awakeFromNib</code> <strong>est appelée automatiquement</strong> lorsque votre application est chargée par <a href="http://fr.wikipedia.org/wiki/Cocoa_(Apple)" xml:lang="en" hreflang="fr" onclick="pageTracker._trackPageview('/outgoing/fr.wikipedia.org/wiki/Cocoa_Apple?referer=');">Cocoa</a> : c&#8217;est donc un emplacement judicieux pour <strong>initialiser des données propres à la vue</strong>. Il faut ensuite implémenter les méthodes suivantes, en fonction des besoins :</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSDragOperation<span style="color: #002200;">&#41;</span>draggingEntered<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> <span style="color: #002200;">&#41;</span>sender <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// Appelée UNE FOIS lorsque la souris commence à survoler la vue</span>
    <span style="color: #11740a; font-style: italic;">// dans un processus de drag and drop.</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSDragOperation<span style="color: #002200;">&#41;</span>draggingExited<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> <span style="color: #002200;">&#41;</span>sender <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// Appelée lorsque la souris quitte la zone de survol de la vue</span>
    <span style="color: #11740a; font-style: italic;">// dans un processus de drag and drop.</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSDragOperation<span style="color: #002200;">&#41;</span>draggingUpdated<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> <span style="color: #002200;">&#41;</span>sender <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// Appelée à chaque fois que la souris est déplacée au dessus de la vue</span>
    <span style="color: #11740a; font-style: italic;">// dans un processus de drag and drop.</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Ces trois méthodes retournent toutes une valeur de type <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Protocols/NSDraggingInfo_Protocol/Reference/Reference.html#//apple_ref/c/tdef/NSDragOperation" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Protocols/NSDraggingInfo_Protocol/Reference/Reference.html_//apple_ref/c/tdef/NSDragOperation?referer=');"><code>NSDragOperation</code></a>, indiquant <strong>si la dépose est autorisée</strong> (<code>NSDragOperationGeneric</code>, &#8230;) <strong>ou pas</strong> (<code>NSDragOperationNone</code>). Ces méthodes peuvent donc servir à<strong> vérifier que la vue accepte bien les données qui sont sur le point d&#8217;être déposées</strong>, auquel cas on retourne une valeur autre que <code>NSDragOperationNone</code> ; si la dépose n&#8217;est pas permise, on retourne <code>NSDragOperationNone</code>.</p>
<p>Enfin, il faut gérer le cas où <strong>l&#8217;utilisateur dépose effectivement les fichiers</strong>, auquel cas la méthode <code>-performDragOperation:</code> est appelée : il convient donc de la surcharger à votre guise&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>performDragOperation<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// Appelée lorsque l'utilisateur a déposer les fichiers sur la vue :</span>
    <span style="color: #11740a; font-style: italic;">// on doit alors récupérer la liste des fichiers et les traiter...</span>
    <span style="color: #400080;">NSPasteboard</span> <span style="color: #002200;">*</span>pboard <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>sender draggingPasteboard<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>pboard types<span style="color: #002200;">&#93;</span> containsObject<span style="color: #002200;">:</span>NSFilenamesPboardType<span style="color: #002200;">&#93;</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>files <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>pboard propertyListForType<span style="color: #002200;">:</span>NSFilenamesPboardType<span style="color: #002200;">&#93;</span>;
        <span style="color: #11740a; font-style: italic;">// files contient maintenant la liste des fichiers (avec chemin complet)</span>
        <span style="color: #11740a; font-style: italic;">// qui ont été déposés sur la vue par l'utilisateur.</span>
        <span style="color: #11740a; font-style: italic;">// Faites donc ici ce que vous voulez avec files ;-)</span>
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>; <span style="color: #11740a; font-style: italic;">// On indique que le drag and drop a été concluant.</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Vous pouvez télécharger le projet complet pour <span xml:lang="en">Xcode</span> : <a href="http://www.glimpse-fr.org/download/tutoriels/DropFilesTutorial.zip" onclick="pageTracker._trackPageview('/outgoing/www.glimpse-fr.org/download/tutoriels/DropFilesTutorial.zip?referer=');"><em>DropFilesTutorial.zip</em></a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fruityfred.com/2009/01/19/glisser-deposer-de-fichiers-dans-votre-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Données membres statiques en Objective-C</title>
		<link>http://www.fruityfred.com/2009/01/12/donnees-membres-statiques-en-objective-c/</link>
		<comments>http://www.fruityfred.com/2009/01/12/donnees-membres-statiques-en-objective-c/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 21:38:46 +0000</pubDate>
		<dc:creator>Fred</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Développement]]></category>
		<category><![CDATA[Tutoriels]]></category>
		<category><![CDATA[POO]]></category>
		<category><![CDATA[statique]]></category>

		<guid isPermaLink="false">http://www.glimpse-fr.org/?p=585</guid>
		<description><![CDATA[Objective-C ne permet pas de déclarer une donnée membre statique dans une classe via l&#8217;utilisation du mot-clé static, comme en Java par exemple. En fait, il suffit de déclarer une variable statique dans la section @implementation de la classe : @implementation MyClass // Déclaration d'une donnée membre STATIQUE static NSDictionary* cacheMap; ... @end Pour initialiser [...]]]></description>
			<content:encoded><![CDATA[<p>Objective-C ne permet pas de déclarer une donnée membre statique dans une classe <em>via</em> l&#8217;utilisation du mot-clé <em>static</em>, comme en <a href="http://java.com/fr/" onclick="pageTracker._trackPageview('/outgoing/java.com/fr/?referer=');">Java</a> par exemple. En fait, il suffit de déclarer une variable statique <strong>dans la section <code>@implementation</code> de la classe</strong> :</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@implementation</span> MyClass
<span style="color: #11740a; font-style: italic;">// Déclaration d'une donnée membre STATIQUE</span>
<span style="color: #a61390;">static</span> <span style="color: #400080;">NSDictionary</span><span style="color: #002200;">*</span> cacheMap;
...
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Pour initialiser cette variable, notamment s&#8217;il s&#8217;agit d&#8217;un objet, il suffit d&#8217;implémenter la méthode statique <em>initialize</em> de la classe concernée et d&#8217;y initialiser la donnée statique :</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> initialize <span style="color: #002200;">&#123;</span>
   cacheMap <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>NSDisctionary dictionary<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Toutes les méthodes statiques de votre classe peuvent utiliser cette donnée statique : <a href="http://fr.wikipedia.org/wiki/Cocoa_(Apple)" xml:lang="en" hreflang="fr" onclick="pageTracker._trackPageview('/outgoing/fr.wikipedia.org/wiki/Cocoa_Apple?referer=');">Cocoa</a> se charge d&#8217;envoyer le message <em>initialize</em> à votre classe <strong>avant tout autre appel</strong>.</p>
<p><strong>Attention</strong> : cette donnée statique <strong>ne sera pas visible dans les classes qui étendent votre classe</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fruityfred.com/2009/01/12/donnees-membres-statiques-en-objective-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dessiner dans une NSView</title>
		<link>http://www.fruityfred.com/2009/01/04/dessiner-dans-une-nsview/</link>
		<comments>http://www.fruityfred.com/2009/01/04/dessiner-dans-une-nsview/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 17:51:44 +0000</pubDate>
		<dc:creator>Fred</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Développement]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Tutoriels]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[Interface Builder]]></category>
		<category><![CDATA[NSImage]]></category>
		<category><![CDATA[NSTimer]]></category>
		<category><![CDATA[NSView]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://www.glimpse-fr.org/?p=559</guid>
		<description><![CDATA[Dans Interface Builder, sélectionnez la vue en question et, dans l&#8217;onglet Identity de l&#8217;Inspecteur, indiquez un nom de classe pour votre vue dans le champ Class (par exemple : GameView). Sélectionnez File > Write Class Files&#8230; dans le menu principal de Interface Builder pour générer cette classe dans le projet. De retour dans Xcode, ouvrez [...]]]></description>
			<content:encoded><![CDATA[<p>Dans <span xml:lang="en"><span xml:lang="en">Interface Builder</span></span>, sélectionnez la vue en question et, dans l&#8217;onglet <em>Identity</em> de l&#8217;Inspecteur, indiquez <strong>un nom de classe</strong> pour votre vue dans le champ <em>Class</em> (par exemple : <code>GameView</code>). Sélectionnez <em>File > Write Class Files&#8230;</em> dans le menu principal de <span xml:lang="en"><span xml:lang="en">Interface Builder</span></span> pour générer cette classe dans le projet.</p>
<p>De retour dans <span xml:lang="en"><span xml:lang="en">Xcode</span></span>, ouvrez le <strong>fichier de déclaration</strong> de cette classe (<code>GameView.h</code>) et faites étendre la classe de <code><a xml:lang="en" hreflang="en" href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/nsview_Class/Reference/NSView.html" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/nsview_Class/Reference/NSView.html?referer=');">NSView</a></code> :</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> GameView <span style="color: #002200;">:</span> <span style="color: #400080;">NSView</span> <span style="color: #002200;">&#123;</span>
   <span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>background;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Ensuite, éditez le <strong>fichier d&#8217;implémentation</strong> de la classe (<code>GameView.m</code>) et implémentez la méthode <code>-drawRect:</code> :</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>awakeFromNib <span style="color: #002200;">&#123;</span>
   <span style="color: #11740a; font-style: italic;">// La variable &quot;background&quot; est déclarée dans le fichier header (.h).</span>
   background <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSImage</span> imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;background.png&quot;</span><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>drawRect<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">NSRect</span><span style="color: #002200;">&#41;</span>rect
<span style="color: #002200;">&#123;</span>
   <span style="color: #002200;">&#91;</span>background dissolveToPoint<span style="color: #002200;">:</span>NSMakePoint<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> fraction<span style="color: #002200;">:</span><span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Notez que l&#8217;image est initialisée dans la méthode <code>-awakeFromNib</code>, qui est appelée lors de l&#8217;initialisation de la vue.</p>
<p>Pour <strong>animer le contenu de la vue</strong>, et donc pour forcer le rafraîchissement de la vue, il est possible d&#8217;utiliser un <code><a xml:lang="en" hreflang="en" href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html#//apple_ref/occ/cl/NSTimer" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html_//apple_ref/occ/cl/NSTimer?referer=');">NSTimer</a></code> pour indiquer à la vue qu&#8217;elle doit se re-dessiner :</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>awakeFromNib <span style="color: #002200;">&#123;</span>
   background <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSImage</span> imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;background.png&quot;</span><span style="color: #002200;">&#93;</span>;
   <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSTimer</span>
      scheduledTimerWithTimeInterval<span style="color: #002200;">:</span><span style="color: #2400d9;">0.01</span>
      target<span style="color: #002200;">:</span>self
      selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>refresh<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span>
      userInfo<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span>
      repeats<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><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>refresh<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSTimer</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>timer <span style="color: #002200;">&#123;</span>
   <span style="color: #002200;">&#91;</span>self setNeedsDisplay<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>La méthode <code>-refresh:</code> sera appelée toutes les 0,01 seconde (100 fois par secondes, donc) et demandera à la vue de se re-dessiner, via l&#8217;appel à <code>setNeedsDisplay:YES</code>. Évidemment, ceci n&#8217;a de sens que si l&#8217;image (ou sa position) change.</p>
<p>Côté <strong>performances</strong>, j&#8217;ai fait quelques tests : j&#8217;affiche 1000 fois la même image (26&#215;26 pixels) toutes les 0.01 seconde en la décalant de 1 pixel et ça ne gêne pas du tout mon <a href="http://www.apple.com/fr/imac/" xml:lang="en" hreflang="fr" onclick="pageTracker._trackPageview('/outgoing/www.apple.com/fr/imac/?referer=');">iMac</a>, <strong>l&#8217;animation est impeccable</strong> !</p>
<p>Je précise que ce n&#8217;est pas ici une technique très avancée pour animer du contenu, car<strong> cela ne tient pas compte de la puissance de la machine</strong>. En vérité, dans la méthode <code>-refresh:</code><strong>, il faudrait vérifier si l&#8217;image doit être déplacée (ou modifiée) en fonction du temps qui s&#8217;est écoulé depuis la dernière modification de cette image</strong>. Ainsi, peu importe la résolution du timer utilisée, ou la capacité de la machine à afficher du contenu graphique, l&#8217;image sera toujours correcte (en fonction du temps écoulé), même si l&#8217;animation n&#8217;est pas fluide. Il est aussi possible d&#8217;utiliser <code><a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSAnimation_Class/Reference/Reference.html" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSAnimation_Class/Reference/Reference.html?referer=');">NSAnimation</a></code> pour des animations complexes &laquo;&nbsp;finies&nbsp;&raquo;.</p>
<p>Pour terminer, si votre but est de faire de l&#8217;animation complexe (2D ou 3D), comme pour la programmation d&#8217;un jeu, je ne peux que vous conseiller de vous tourner vers <a href="http://www.opengl.org/" onclick="pageTracker._trackPageview('/outgoing/www.opengl.org/?referer=');">OpenGL</a>. Je suis en train de m&#8217;y mettre, je publierai donc prochainement des articles à ce propos.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fruityfred.com/2009/01/04/dessiner-dans-une-nsview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gestion des préférences d&#8217;une application Cocoa</title>
		<link>http://www.fruityfred.com/2008/09/30/gestion-des-preferences-dune-application-cocoa/</link>
		<comments>http://www.fruityfred.com/2008/09/30/gestion-des-preferences-dune-application-cocoa/#comments</comments>
		<pubDate>Mon, 29 Sep 2008 23:35:00 +0000</pubDate>
		<dc:creator>Fred</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Développement]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Tutoriels]]></category>

		<guid isPermaLink="false">http://www.glimpse-fr.org/?p=229</guid>
		<description><![CDATA[Pour les développeurs qui débutent sous Mac OS X, voici un didacticiel pour apprendre à gérer les préférences d&#8217;une application Cocoa. Il est nécessaire d&#8217;avoir quelques (bonnes) notions en Objective-C, Cocoa, Xcode et Interface Builder. Attention : ce didacticiel n&#8217;explique pas comment faire un panneau pour les préférences système.]]></description>
			<content:encoded><![CDATA[<p>Pour les développeurs qui débutent sous <span class="nobr"><a href="http://www.apple.com/fr/macosx/" hreflang="fr" onclick="pageTracker._trackPageview('/outgoing/www.apple.com/fr/macosx/?referer=');">Mac OS X</a></span>, <a href="http://www.glimpse-fr.org/developpement/preferences-application-cocoa/" onclick="pageTracker._trackPageview('/outgoing/www.glimpse-fr.org/developpement/preferences-application-cocoa/?referer=');">voici un didacticiel</a> pour apprendre à gérer les préférences d&#8217;une application <a href="http://fr.wikipedia.org/wiki/Cocoa_(Apple)" xml:lang="en" hreflang="fr" onclick="pageTracker._trackPageview('/outgoing/fr.wikipedia.org/wiki/Cocoa_Apple?referer=');">Cocoa</a>. Il est nécessaire d&#8217;avoir quelques (bonnes) notions en Objective-C, <a href="http://fr.wikipedia.org/wiki/Cocoa_(Apple)" xml:lang="en" hreflang="fr" onclick="pageTracker._trackPageview('/outgoing/fr.wikipedia.org/wiki/Cocoa_Apple?referer=');">Cocoa</a>, <span xml:lang="en">Xcode</span> et <span xml:lang="en">Interface Builder</span>. Attention : ce didacticiel n&#8217;explique pas comment faire un panneau pour les préférences système.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fruityfred.com/2008/09/30/gestion-des-preferences-dune-application-cocoa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

