<?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>DaveOnCode</title>
	<atom:link href="http://www.daveoncode.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.daveoncode.com</link>
	<description>Objective C, iOS and more programming stuff</description>
	<lastBuildDate>Mon, 19 Dec 2011 12:11:12 +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>Fundamental iOS design patterns: SharedInstance (Singleton in Objective C)</title>
		<link>http://www.daveoncode.com/2011/12/19/fundamental-ios-design-patterns-sharedinstance-singleton-objective-c/</link>
		<comments>http://www.daveoncode.com/2011/12/19/fundamental-ios-design-patterns-sharedinstance-singleton-objective-c/#comments</comments>
		<pubDate>Mon, 19 Dec 2011 12:11:12 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[Objective-c and Cocoa]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=875</guid>
		<description><![CDATA[Brief introduction Singleton is one of the (if not THE) most commonly used/abused design pattern adopted in software development. Basically it&#8217;s used to restrict the instantiation of a class to one object only that can be used safely across application architecture. Its implementation is pretty simple compared to other patterns and it&#8217;s very similar for [...]]]></description>
			<content:encoded><![CDATA[<h2>Brief introduction</h2>
<p>Singleton is one of the (if not THE) most commonly used/abused design pattern adopted in software development.<br />
Basically it&#8217;s used to restrict the instantiation of a class to one object only that can be used safely across application architecture. Its implementation is pretty simple compared to other patterns and it&#8217;s very similar for the most of programming languages, but in Objective C it has a slightly different approach due to the lack of &#8220;normal constructor&#8221; that are instead replaced by alloc/init paradigm.</p>
<h2>How it works in Objective C</h2>
<p>In Objective C, we can speak more appropriately about the SharedInstance pattern rather than traditional Singleton.<br />
This one is often used in Apple frameworks and differently from its twin brother, it does not explicitly forbid the instantiation of multiple class instances, but it simply provide a class method that will return a shared instance. During the first call to that method the instance will be allocated and the next calls will return the previously object created. So this is a sort of hybrid approach.<br />
A common class that use this pattern is <strong>UIApplication</strong> which implements a <strong>sharedApplication</strong> method (which returns the current running application). Differently from Singleton which use <strong>getInstance()</strong>, in Objective C the corresponding method has not a fixed name but it should start with &#8220;<strong>shared</strong>&#8221; followed by the &#8220;type&#8221; of class (so for <strong>UIApplication</strong> is &#8220;<strong>sharedApplication</strong>&#8221; for <strong>MYAmazingManager</strong> will be &#8220;<strong>sharedManager</strong>&#8220;). Anyway there are several exceptions, for example <strong>NSFileManager</strong> has a &#8220;<strong>defaultManager</strong>&#8221; acting as a sharedInstance accessor that could be renamed &#8220;<strong>sharedManager</strong>&#8220;.</p>
<h2>Pattern implementation</h2>
<p>In my singleton implementations I simply call the accessor &#8220;<strong>sharedInstance</strong>&#8220;, in this way I can use a simple pre-compiler macro that automatically synthesize this methods for me.<br />
Even implementation of this pattern may vary and personally I adopted one which is <strong style="text-decoration:underline">thread-safe</strong> and rely on <a href="http://developer.apple.com/library/mac/#documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html"><strong>CGD</strong> (<strong>Grand Central Dispatch</strong>)</a>, which is an affective C level API provided by Apple in order to handle concurrency.</p>
<p>The implementation of my sharedInstance method is the following (comments explain how it works):</p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span>sharedInstance <br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// structure used to test whether the block has completed or not</span><br />
&nbsp; &nbsp; <span style="color: #993333;">static</span> dispatch_once_t p <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// initialize sharedObject as nil (first call only)</span><br />
&nbsp; &nbsp; __strong <span style="color: #993333;">static</span> id _sharedObject <span style="color: #339933;">=</span> nil<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// executes a block object once and only once for the lifetime of an application</span><br />
&nbsp; &nbsp; dispatch_once<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>p<span style="color: #339933;">,</span> <span style="color: #339933;">^</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _sharedObject <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>self alloc<span style="color: #009900;">&#93;</span> init<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// returns the same object each time</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> _sharedObject<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<h2>Pattern in action!</h2>
<p>SharedInstance pattern is IMO the best way to share data across multiple viewControllers in iOS applications.<br />
One practical example is a data manager to share Core Data stuff such managed object context. I realized my own manager so that I can access this objects anywhere with ease like:</p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>MYDataManager sharedInstance<span style="color: #009900;">&#93;</span> managedObjectContext<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2011/12/19/fundamental-ios-design-patterns-sharedinstance-singleton-objective-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick iOS tip: where is the right place to add and remove observers in UIViewControllers?</title>
		<link>http://www.daveoncode.com/2011/12/12/quick-ios-tip-where-is-the-right-place-to-add-and-remove-observers-in-uiviewcontrollers/</link>
		<comments>http://www.daveoncode.com/2011/12/12/quick-ios-tip-where-is-the-right-place-to-add-and-remove-observers-in-uiviewcontrollers/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 19:30:06 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[Objective-c and Cocoa]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=906</guid>
		<description><![CDATA[While I was debugging my iPhone app I noticed (thanks to my verbose logs) that certain methods were called multiple times&#8230; apparently like if they were in a loop. I lost several time trying to figure out why and then I realized that the problem was related to defining them in the wrong place! (technically [...]]]></description>
			<content:encoded><![CDATA[<p>While I was debugging my iPhone app I noticed (thanks to my verbose logs) that certain methods were called multiple times&#8230; apparently like if they were in a loop. I lost several time trying to figure out why and then I realized that the problem was related to defining them in the wrong place! (technically not wrong at all, but definitely wrong in my app context).<br />
I was adding listeners in <strong>viewDidLoad</strong> and removing them in <strong>viewDidUnload</strong>.<br />
This is acceptable only if you have simple UIViewControllers that don&#8217;t work in composite controllers hierarchy (they are not contained in <strong>UINavigationController</strong> or <strong>UITabBarController</strong>).<br />
viewDidLoad is called after the view controller’s view has been released, but in a controllers hierarchy this does not happen since controllers are retained by the container! This leads to multiple messages dispatched to registered observers, so if you have a UINavigationController containing a sequence of 5 viewController, handlers will be triggered 5 times (one for each controller).<br />
The safely approach to add and remove listeners is instead in <strong>viewWillAppear:</strong> and <strong>viewWillDisappear:</strong><br />
Example:</p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>viewWillAppear<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>BOOL<span style="color: #009900;">&#41;</span>animated<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#91;</span>super viewWillAppear<span style="color: #339933;">:</span>animated<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>NSNotificationCenter defaultCenter<span style="color: #009900;">&#93;</span> addObserver<span style="color: #339933;">:</span>self selector<span style="color: #339933;">:</span>@selector<span style="color: #009900;">&#40;</span>foo<span style="color: #339933;">:</span><span style="color: #009900;">&#41;</span> name<span style="color: #339933;">:</span>UIKeyboardDidShowNotification object<span style="color: #339933;">:</span>nil<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>viewWillDisappear<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>BOOL<span style="color: #009900;">&#41;</span>animated<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#91;</span>super viewWillDisappear<span style="color: #339933;">:</span>animated<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>NSNotificationCenter defaultCenter<span style="color: #009900;">&#93;</span> removeObserver<span style="color: #339933;">:</span>self name<span style="color: #339933;">:</span>UIKeyboardDidShowNotification object<span style="color: #339933;">:</span>nil<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2011/12/12/quick-ios-tip-where-is-the-right-place-to-add-and-remove-observers-in-uiviewcontrollers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generate beautiful code documentation with a simple shortcut using AppleDoc, Xcode custom behaviors and AppleScript!</title>
		<link>http://www.daveoncode.com/2011/12/08/generate-beautiful-code-documentation-with-simple-shortcut-using-appledoc-xcode-custom-behaviours-applescript/</link>
		<comments>http://www.daveoncode.com/2011/12/08/generate-beautiful-code-documentation-with-simple-shortcut-using-appledoc-xcode-custom-behaviours-applescript/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 10:48:15 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[xcode]]></category>
		<category><![CDATA[AppleDoc]]></category>
		<category><![CDATA[AppleScript]]></category>
		<category><![CDATA[ide]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=890</guid>
		<description><![CDATA[This time I realized something really great and I&#8217;m truly satisfied about it! Few days ago I discovered a fantastic open source project from GentleBytes called AppleDoc by reading a post on Cocoanetics. This is a tool that generate an Apple-like HTML documentation from source files (by using the proper comment style) and it also [...]]]></description>
			<content:encoded><![CDATA[<p>This time I realized something really great and I&#8217;m truly satisfied about it!<br />
Few days ago I discovered a fantastic open source project from <a href="http://gentlebytes.com/">GentleBytes</a> called <a href="http://gentlebytes.com/appledoc/">AppleDoc</a> by reading a post on <a href="http://www.cocoanetics.com/2011/11/amazing-apple-like-documentation/">Cocoanetics</a>.<br />
This is a tool that generate an Apple-like HTML documentation from source files (by using the proper comment style) and it also generates installable docsets and Atom feeds for the download from a remote host.<br />
After a couple of tests and document generations my big question was: &#8220;how can I automatize the process without launching a script every time and for each project I want to document?&#8221;.<br />
The first obvious answer was &#8220;add a <strong>Run Script</strong> in the build phases!&#8221;&#8230; but it&#8217;s not a smart idea to launch a similar long script for every build, because it takes several seconds and potentially minutes depending on the amount of classes to analyze, and it&#8217;s often unnecessary to update a documentation if method signatures remain the same. So I searched for an alternative way to execute scripts from Xcode only when desired, by focusing my efforts on its &#8220;<strong>Behaviors</strong>&#8221; (<strong>Xcode > Behaviors > Edit Behaviors > +</strong>). Behaviors can be triggered by events (only default behaviors), using menu or with a custom shortcut and a behavior can perform several actions like running a script&#8230;<br />
and here I started to waste a lot of time in order to realize what I had in mind (create a single auto-runnable script to generate code documentation for each project without hard-coding paths and names), because the <a href="http://developer.apple.com/library/mac/#documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html">environment variables</a> I was using in Xcode build phases as a test can&#8217;t be used in external scripts (since they are not attached to the Xcode process as far I understood).<br />
So the problem was: &#8220;how can I retrieve this variables dynamically from our beloved ide? is it possible?&#8221;&#8230; it&#8217;s been an hard google search plus a couple of questions asked on <a href="http://www.stackoverflow.com">StackOverflow</a> (Did I tell you how much I love that site? I really love it!) in order to clear my dubs&#8230; and yes, it&#8217;s possible thanks to <strong>AppleScript</strong>! Xcode exposes several objects that can be queried by this funny script language, so in this way I first realized an <strong>AppleScript</strong> to retrieve the variables I need (project name, project path and company) and then I invoked my old and refactored bash script passing them.<br />
In conclusion I&#8217;m now able to launch document generation for each project I&#8217;m working on, by simply press <strong>ALT+CMD+D</strong> (a custom shortcut of my choice), I also configured a submarine sound effect and the display of a bezel alert&#8230; really wonderful!</p>
<p>This is the AppleScript used for the behavior that invoke the bash script by sending it the necessary arguments:</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#!/usr/bin/osascript<br />
<br />
tell application &quot;Xcode&quot;<br />
&nbsp; &nbsp; tell first project<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; -- variables to export<br />
&nbsp; &nbsp; &nbsp; &nbsp; set projectName to (get name)<br />
&nbsp; &nbsp; &nbsp; &nbsp; set projectDir to (get project directory)<br />
&nbsp; &nbsp; &nbsp; &nbsp; set company to (get organization name)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; -- invoke script passing extracted variables<br />
&nbsp; &nbsp; &nbsp; &nbsp; do shell script (&quot;sh /PATH_TO_SCRIPT/appledoc.generate.sh &quot; &amp; projectName &amp; &quot; &quot; &amp; projectDir &amp; &quot; &quot; &amp; company)<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; end tell<br />
end tell</div></td></tr></tbody></table></div>
<p>Of course you have to replace &#8220;/PATH_TO_SCRIPT/appledoc.generate.sh&#8221; according to your path.<br />
If you decide to create your own AppleScript script using the default editor (/Applications/Utilities/Apple Script Editor), remember to save it as a plain text and to include the proper header declaration (<strong>#!/usr/bin/osascript</strong>), otherwise Xcode will throw an exception trying to run it!</p>
<p>&#8230;and this is <strike>Sparta</strike> the bash (I added a couple of <strong>say</strong> commands in order to debug the process&#8230; remove comments to hear your mac speak!):</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#! /bin/sh<br />
<br />
# Input arguments: <br />
# $1 -&gt; project name<br />
# $2 -&gt; project path<br />
# $3 -&gt; company name<br />
<br />
# dynamic variables<br />
docsURL=&quot;http://www.$3.com/docs&quot;;<br />
projectsPath=&quot;$2/../&quot;;<br />
docsPath=&quot;${projectsPath}/AppleDocOutput&quot;;<br />
<br />
#say &quot;project is: $1&quot;;<br />
#say &quot;path is: $2&quot;;<br />
#say &quot;company is: $3&quot;;<br />
#say &quot;project path is: ${projectsPath}&quot;;<br />
<br />
# create AppleDocOutput folder if not exists<br />
if [ ! -d $docsPath ];<br />
then<br />
&nbsp; &nbsp; #say &quot;create output folder&quot;;<br />
&nbsp; &nbsp; mkdir &quot;${docsPath}&quot;;<br />
fi<br />
<br />
#say &quot;run appledoc&quot;;<br />
<br />
#invoke appledoc passing computed arguments<br />
/usr/bin/appledoc \<br />
--project-name &quot;$1&quot; \<br />
--output &quot;${docsPath}/$1/&quot; \<br />
--docset-feed-url &quot;${docsURL}/%DOCSETATOMFILENAME&quot; \<br />
--docset-package-url &quot;${docsURL}/%DOCSETPACKAGEFILENAME&quot; \<br />
--docset-fallback-url &quot;${docsURL}/$1Doc/&quot; \<br />
--ignore &quot;$1Tests&quot; \<br />
&quot;$2&quot; &gt; &quot;${docsPath}/AppleDoc.log&quot;</div></td></tr></tbody></table></div>
<p>the bash invokes AppleDoc by assuming its location on /usr/bin/appledoc, the arguments passed are few since I use the GlobalSettings.plist for the main setting and I override only certain options (read GentleBytes reference for more info).<br />
I also redirect the output of the command to a log file for an easy debug.<br />
Remember to make both scripts executable (<strong>chmod +x</strong>) in order to use them!</p>
<p>&#8230;that&#8217;s all! If you want more info leave a comment (it&#8217;s free)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2011/12/08/generate-beautiful-code-documentation-with-simple-shortcut-using-appledoc-xcode-custom-behaviours-applescript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Quick iOS tip: invoke UITableView dataSource and delegate methods from a UITableViewCell</title>
		<link>http://www.daveoncode.com/2011/11/28/quick-ios-tip-invoke-uitableview-datasource-delegate-methods-from-uitableviewcell/</link>
		<comments>http://www.daveoncode.com/2011/11/28/quick-ios-tip-invoke-uitableview-datasource-delegate-methods-from-uitableviewcell/#comments</comments>
		<pubDate>Mon, 28 Nov 2011 13:03:43 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[Objective-c and Cocoa]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[UITableView]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=866</guid>
		<description><![CDATA[I faced a situation in my app where I wanted to access to UITableView datasource from a UITableViewCell. Specifically I implemented the same behavior of left green (+) button in the label contained in the cell, so if you click on it the editing action &#8220;UITableViewCellEditingStyleInsert&#8221; will be committed. Since a cell is contained in [...]]]></description>
			<content:encoded><![CDATA[<p>I faced a situation in my app where I wanted to access to <strong>UITableView</strong> datasource from a <strong>UITableViewCell</strong>. Specifically I implemented the same behavior of left green (+) button in the label contained in the cell, so if you click on it the editing action &#8220;<strong>UITableViewCellEditingStyleInsert</strong>&#8221; will be committed.<br />
Since a cell is contained in a table we can easily access to it using <strong>self.superview</strong> (cast is required because superview returns a basic <strong>UIView</strong> *), then once we are sure that the table has a valid dataSource, we can manually invoke the selector <strong>tableView:commitEditingStyle:forRowAtIndexPath:</strong>. In order to pass the proper <strong>indexPath</strong> dynamically we rely on table method <strong>indexPathForCell:</strong> (we don&#8217;t know in which cell we are but table does!).<br />
The complete code snippet is the following:</p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">UITableView <span style="color: #339933;">*</span>table <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>UITableView <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>self.<span style="color: #202020;">superview</span><span style="color: #339933;">;</span><br />
SEL sel <span style="color: #339933;">=</span> @selector<span style="color: #009900;">&#40;</span>tableView<span style="color: #339933;">:</span>commitEditingStyle<span style="color: #339933;">:</span>forRowAtIndexPath<span style="color: #339933;">:</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>table isKindOfClass<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>UITableView class<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#91;</span>table.<span style="color: #202020;">dataSource</span> respondsToSelector<span style="color: #339933;">:</span>sel<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#91;</span>table.<span style="color: #202020;">dataSource</span> tableView<span style="color: #339933;">:</span>table <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;commitEditingStyle<span style="color: #339933;">:</span>UITableViewCellEditingStyleInsert <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; forRowAtIndexPath<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>table indexPathForCell<span style="color: #339933;">:</span>self<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2011/11/28/quick-ios-tip-invoke-uitableview-datasource-delegate-methods-from-uitableviewcell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xcode key bindings: how to create a custom shortcut to convert upper case text to lower case and viceversa</title>
		<link>http://www.daveoncode.com/2011/11/04/xcode-key-bindings-custom-shortcut-convert-upper-case-text-to-lower-case/</link>
		<comments>http://www.daveoncode.com/2011/11/04/xcode-key-bindings-custom-shortcut-convert-upper-case-text-to-lower-case/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 14:41:11 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[xcode]]></category>
		<category><![CDATA[ide]]></category>
		<category><![CDATA[shortcut]]></category>

		<guid isPermaLink="false">http://www.daveoncode.com/?p=854</guid>
		<description><![CDATA[Since one of the most visited post on my blog is that one about case conversion in Eclipse, I decided to share how to implement 2 custom shortcuts to do the same in Xcode. In &#8220;Preferences&#8221; panel, there is a tab called &#8220;Key Bindings&#8220;, here we can configure keys used for shortcuts. By default the [...]]]></description>
			<content:encoded><![CDATA[<p>Since one of the most visited post on my blog is that one about case conversion in Eclipse, I decided to share how to implement 2 custom shortcuts to do the same in Xcode.<br />
In &#8220;<strong>Preferences</strong>&#8221; panel, there is a tab called &#8220;<strong>Key Bindings</strong>&#8220;, here we can configure keys used for shortcuts. By default the most are already configured, but that&#8217;s not the case for text case conversion. By typing &#8220;<strong>case</strong>&#8221; to filter the long list, you can see 2 commands: &#8220;<strong>Lowercase word</strong>&#8221; and &#8220;<strong>Uppercase word</strong>&#8220;, all you have to do is to click on the &#8220;<strong>key</strong>&#8221; column and register your shortcut.<br />
To avoid conflicts and to make them simple to remember I did choose &#8220;<strong>SHIFT + CTRL + L</strong>&#8221; for the first and  &#8220;<strong>SHIFT + CTRL + U</strong>&#8221; for the second (but you can register your own one).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2011/11/04/xcode-key-bindings-custom-shortcut-convert-upper-case-text-to-lower-case/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

