<?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>Rick&#039;s Scrapbook</title>
	<atom:link href="http://rickbgs.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://rickbgs.com</link>
	<description>Don’t live to geek, geek to live!</description>
	<lastBuildDate>Sun, 19 Feb 2012 01:43:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>NSLog Format Specifiers</title>
		<link>http://rickbgs.com/2012/02/nslog-format-specifiers/</link>
		<comments>http://rickbgs.com/2012/02/nslog-format-specifiers/#comments</comments>
		<pubDate>Sun, 19 Feb 2012 01:43:20 +0000</pubDate>
		<dc:creator>Ricardo Silva</dc:creator>
				<category><![CDATA[Objective C]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://rickbgs.com/?p=43</guid>
		<description><![CDATA[%@ Object %d, %i signed int %u unsigned int %f float/double %x, %X hexadecimal int %o octal int %zu size_t %p pointer %e float/double (in scientific notation) %g float/double (as %f or %e, depending on value) %s C string (bytes) %S C string (unichar) %.*s Pascal string (requires two arguments, pass pstr[0] as the first, [...]]]></description>
			<content:encoded><![CDATA[<pre>%@     Object
%d, %i signed int
%u     unsigned int
%f     float/double

%x, %X hexadecimal int
%o     octal int
%zu    size_t
%p     pointer
%e     float/double (in scientific notation)
%g     float/double (as %f or %e, depending on value)
%s     C string (bytes)
%S     C string (unichar)
%.*s   Pascal string (requires two arguments, pass pstr[0] as the first, pstr+1 as the second)
%c     character
%C     unichar

%lld   long long
%llu   unsigned long long
%Lf    long double</pre>
]]></content:encoded>
			<wfw:commentRss>http://rickbgs.com/2012/02/nslog-format-specifiers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Static Libraries &amp; Workspaces</title>
		<link>http://rickbgs.com/2011/11/static-libraries-workspaces/</link>
		<comments>http://rickbgs.com/2011/11/static-libraries-workspaces/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 17:22:33 +0000</pubDate>
		<dc:creator>Ricardo Silva</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[libraries]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://rickbgs.com/?p=40</guid>
		<description><![CDATA[They say that you should not duplicate your code, but when it comes to iOS development what I see is a lot of duplicated files from third party libraries… For example, JSON and ASIHTTPRequest. So we end up with loads of duplicated files or, if not duplicated, very similar, differing in version. Static Libraries would [...]]]></description>
			<content:encoded><![CDATA[<p>They say that you should not duplicate your code, but when it comes to iOS development what I see is a lot of duplicated files from third party libraries… For example, JSON and ASIHTTPRequest. So we end up with loads of duplicated files or, if not duplicated, very similar, differing in version.</p>
<p>Static Libraries would help the programmer with this problem.</p>
<p>To create your static library project, you choose the <code>Cocoa Touch Static Library</code> template under <code>Framework &amp; Library</code>. What you need to note about this project is:</p>
<ul>
<li>Set the headers (you want to be public) to <code>public</code>. This can be set during the <code>Copy Headers</code> under <code>Build Phases</code> of your static library target.</li>
<li>Set the <code>Installation Directory</code> to <code>$(BUILT_PRODUCTS_DIR)</code>.</li>
<li><code>Skip Install</code> should be set to <code>Yes</code>.</li>
<li><code>Public Headers Folder Path</code> should be set to <code>$(TARGET_NAME)</code>.</li>
</ul>
<p>This project can then be used by other projects. I recommend you to set up a workspace for this. You can either save a current project as a workspace or create a workspace and drag and drop your project (the .xcodeproj file) to it. Be careful when you drag the static library project not to drag it inside another project. It should be at the same level of the main project.</p>
<p>Then, follow these steps for your project:</p>
<ul>
<li>Add your library to <code>Link Binary With Libraries</code>.</li>
<li>Set <code>User Header Search Paths</code> to <code>$(BUILT_PRODUCTS_DIR)</code> recursively.</li>
<li>You may need to add <code>-ObjC</code> to <code>Other Linker Flags</code> if you use categories. You may also need to add <code>-all_load</code> and <code>-force_load</code> in some situations.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://rickbgs.com/2011/11/static-libraries-workspaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic Reference Counting and Frameworks</title>
		<link>http://rickbgs.com/2011/10/arc-and-frameworks/</link>
		<comments>http://rickbgs.com/2011/10/arc-and-frameworks/#comments</comments>
		<pubDate>Wed, 12 Oct 2011 13:41:53 +0000</pubDate>
		<dc:creator>Ricardo Silva</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://rickbgs.com/?p=33</guid>
		<description><![CDATA[ARC is a compile-time technology, which actually results in a notable performance benefit. The compiler generates calls to retain/release/autorelease on your behalf, instead of you inserting them manually. Nothing new happens at run-time, which is why ARC can be enabled/disabled on a file-by-file basis when compiling an Xcode project. If you need to use other [...]]]></description>
			<content:encoded><![CDATA[<p>ARC is a compile-time technology, which actually results in a notable performance benefit. The compiler generates calls to <code>retain</code>/<code>release</code>/<code>autorelease</code> on your behalf, instead of you inserting them manually. Nothing new happens at run-time, which is why ARC can be enabled/disabled on a file-by-file basis when compiling an Xcode project.</p>
<p>If you need to use other third party frameworks that are not available as static libraries and don&#8217;t support ARC in projects supporting ARC, you can specify compile flags per files.</p>
<p>With Xcode 4.2, you can use <code>-fno-objc-arc</code> only for the framework, like JSONKit, for example.</p>
<p>Steps:</p>
<ol>
<li>Select project;</li>
<li>Select target;</li>
<li>Open “Build Phases” tab;</li>
<li>Open “Compile Sources (nn items)”;</li>
<li>On second column, you can specify “Compiler Flags”. Set to <code>-fno-objc-arc</code> for each file you want.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://rickbgs.com/2011/10/arc-and-frameworks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Good bye, EXC_BAD_ACCESS!</title>
		<link>http://rickbgs.com/2011/08/good-bye-exc_bad_access/</link>
		<comments>http://rickbgs.com/2011/08/good-bye-exc_bad_access/#comments</comments>
		<pubDate>Sun, 28 Aug 2011 21:12:22 +0000</pubDate>
		<dc:creator>Ricardo Silva</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://rickbgs.com/?p=28</guid>
		<description><![CDATA[The EXC_BAD_ACCESS error means that a message was sent to a point in the memory where there’s no instance of a class to execute it. Thus “bad access”. Most of the times, the message was sent to an abject that has been already released or was never initialised. In the over released objects situations, zombies [...]]]></description>
			<content:encoded><![CDATA[<p>The EXC_BAD_ACCESS error means that a message was sent to a point in the memory where there’s no instance of a class to execute it. Thus “bad access”. Most of the times, the message was sent to an abject that has been already released or was never initialised.</p>
<p>In the over released objects situations, zombies are very handy… When you enable this feature, a dummy object (a zombie) is kept on the place of every released object, allowing to debug objects which were released already. To enable the zombies, edit the scheme: in “Run”, open “Arguments” tab and add <code>NSZombieEnabled</code> with value <code>YES</code> in the “Environment Variables” section. Voila!</p>
<p>Important: remind not to leave the zombies enabled when you submit your app to the App store. Also, it’s a good practice to disable them if you don’t really need them.</p>
]]></content:encoded>
			<wfw:commentRss>http://rickbgs.com/2011/08/good-bye-exc_bad_access/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Correct use of MapKit</title>
		<link>http://rickbgs.com/2011/06/correct-use-of-mapkit/</link>
		<comments>http://rickbgs.com/2011/06/correct-use-of-mapkit/#comments</comments>
		<pubDate>Fri, 24 Jun 2011 09:55:46 +0000</pubDate>
		<dc:creator>Ricardo Silva</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://rickbgs.com/?p=20</guid>
		<description><![CDATA[I&#8217;ve seen some apps being rejected because MapKit was used in a way it violates the Google&#8217;s terms of service for Maps. Commonly it is because the Google logo is hidden or covered. When using MapKit you need to make sure that Google logo will be visible always. You can prevent it being hidden by [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve seen some apps being rejected because MapKit was used in a way it violates the <a href="http://code.google.com/apis/maps/terms.html">Google&#8217;s terms of service for Maps</a>. Commonly it is because the Google logo is hidden or covered.</p>
<p>When using MapKit you need to make sure that Google logo will be visible always. You can prevent it being hidden by resizing operations using the following resizing mask:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">mapView.autoresizingMask <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight<span style="color: #002200;">&#41;</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rickbgs.com/2011/06/correct-use-of-mapkit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Presenting HttpServletResponse as file download</title>
		<link>http://rickbgs.com/2011/06/presenting-httpservletresponse-as-file-download/</link>
		<comments>http://rickbgs.com/2011/06/presenting-httpservletresponse-as-file-download/#comments</comments>
		<pubDate>Fri, 17 Jun 2011 13:18:42 +0000</pubDate>
		<dc:creator>Ricardo Silva</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[servlets]]></category>

		<guid isPermaLink="false">http://rickbgs.com/?p=13</guid>
		<description><![CDATA[The following code will present the response as a file to be download instead of being displayed in the browser. The key here is the Content-disposition header. protected void doGet&#40;final HttpServletRequest req, final HttpServletResponse resp&#41; throws ServletException, IOException &#123; byte&#91;&#93; data = null; // load data &#160; resp.reset&#40;&#41;; resp.setContentType&#40;&#34;image/png&#34;&#41;; resp.setHeader&#40;&#34;Content-disposition&#34;, &#34;attachment; filename=image.png&#34;&#41;; &#160; final OutputStream [...]]]></description>
			<content:encoded><![CDATA[<p>The following code will present the response as a file to be download instead of being displayed in the browser. The key here is the <code>Content-disposition</code> header.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> HttpServletRequest req, <span style="color: #000000; font-weight: bold;">final</span> HttpServletResponse resp<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> data <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// load data</span>
&nbsp;
	resp.<span style="color: #006633;">reset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	resp.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;image/png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	resp.<span style="color: #006633;">setHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-disposition&quot;</span>, <span style="color: #0000ff;">&quot;attachment; filename=image.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">OutputStream</span> output <span style="color: #339933;">=</span> resp.<span style="color: #006633;">getOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	output.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	output.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rickbgs.com/2011/06/presenting-httpservletresponse-as-file-download/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Conditional Compilation</title>
		<link>http://rickbgs.com/2011/06/conditional-compilation/</link>
		<comments>http://rickbgs.com/2011/06/conditional-compilation/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 16:04:28 +0000</pubDate>
		<dc:creator>Ricardo Silva</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[conditional compilation]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[macros]]></category>

		<guid isPermaLink="false">http://rickbgs.com/?p=8</guid>
		<description><![CDATA[Sometimes you need different settings for different purposes (for example, when you&#8217;re testing your app). You could use a server for development and another for production, try to do something hard code when you are testing In App Purchases or something else… Conditional compilation is very useful in these scenarios. While blocks of “if” from [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you need different settings for different purposes (for example, when you&#8217;re testing your app). You could use a server for development and another for production, try to do something hard code when you are testing In App Purchases or something else…</p>
<p>Conditional compilation is very useful in these scenarios. While blocks of “if” from programming languages are part from the binary file but only one block is executed at time (but both could be, in different moments), the conditional “if” is executed during compilation and so the negated block won&#8217;t be part of te binary file.</p>
<p>You need to add a compilation flag in your project settings. In the example below, the flag <code>-DDEBUG_BUILD</code> was added to the target settings.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#ifdef DEBUG_BUILD</span>
    <span style="color: #6e371a;">#define SERVER_URL_STRING @&quot;http://development.server.com&quot;</span>
<span style="color: #6e371a;">#else</span>
    <span style="color: #6e371a;">#define SERVER_URL_STRING @&quot;http://production.server.com&quot;</span>
<span style="color: #6e371a;">#endif</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rickbgs.com/2011/06/conditional-compilation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NSLog(&#8220;Hello world!&#8221;)</title>
		<link>http://rickbgs.com/2011/05/nsloghello-world/</link>
		<comments>http://rickbgs.com/2011/05/nsloghello-world/#comments</comments>
		<pubDate>Fri, 27 May 2011 10:21:51 +0000</pubDate>
		<dc:creator>Ricardo Silva</dc:creator>
				<category><![CDATA[Objective C]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[conditional compilation]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[macros]]></category>

		<guid isPermaLink="false">http://rickbgs.com/?p=6</guid>
		<description><![CDATA[Everybody knows logging is an import step during any software development, specially in the debug phase. However, its removal can be very tricky after the debug phase is finished and logging is no longer needed and you might need to get rid of it. That&#8217;s when macros are very helpful… #ifdef DEBUG # define DLog(fmt, [...]]]></description>
			<content:encoded><![CDATA[<p>Everybody knows logging is an import step during any software development, specially in the debug phase. However, its removal can be very tricky after the debug phase is finished and logging is no longer needed and you might need to get rid of it. That&#8217;s when macros are very helpful…</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#ifdef DEBUG</span>
<span style="color: #6e371a;">#   define DLog(fmt, ...) NSLog((@&quot;%s [Line %d] &quot; fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);</span>
<span style="color: #6e371a;">#else</span>
<span style="color: #6e371a;">#   define DLog(...)</span>
<span style="color: #6e371a;">#endif</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// ALog always displays output regardless of the DEBUG setting</span>
<span style="color: #6e371a;">#define ALog(fmt, ...) NSLog((@&quot;%s [Line %d] &quot; fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);</span></pre></div></div>

<p>With the code above, you can use <code>DLog</code> to log only while debugging and <code>ALog</code> to log always.</p>
<p>You can put this code to your <code>.pch</code> file or creat a new file (for example, <code>Log.h</code>) that you can reuse among various projects and import it whenever you need or in the <code>.pch</code> file again.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import “Log.h”</span></pre></div></div>

<p>For this to work you need to add the <code>-DDEBUG</code> flag in the “Other C Flags” option in your project’s configuration.</p>
<p>Another simpler way would be:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#ifdef DEBUG</span>
<span style="color: #6e371a;">#	define DLog(...) NSLog(__VA_ARGS__)</span>
<span style="color: #6e371a;">#else</span>
<span style="color: #6e371a;">#	define DLog(...) /* */</span>
<span style="color: #6e371a;">#endif</span>
<span style="color: #6e371a;">#define ALog(...) NSLog(__VA_ARGS__)</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rickbgs.com/2011/05/nsloghello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

