<?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>ObjColumnist &#187; Quick Tip</title>
	<atom:link href="http://objcolumnist.com/category/quick-tip/feed/" rel="self" type="application/rss+xml" />
	<link>http://objcolumnist.com</link>
	<description>Coding under the Hammer</description>
	<lastBuildDate>Fri, 09 Mar 2012 12:57:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Rounding the corners of an UIView</title>
		<link>http://objcolumnist.com/2010/08/15/rounding-the-corners-of-an-uiview/</link>
		<comments>http://objcolumnist.com/2010/08/15/rounding-the-corners-of-an-uiview/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 15:20:12 +0000</pubDate>
		<dc:creator>Spencer MacDonald</dc:creator>
				<category><![CDATA[CocoaTouch]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Quick Tip]]></category>

		<guid isPermaLink="false">http://objcolumnist.com/?p=228</guid>
		<description><![CDATA[Rounded corners are all the rage at the moment, so you would think that there would be an API on UIView to do such a thing. If you looked at all of the UIView documentation, you would come to the conclusion that there is not an API to do such a thing, and you would [...]]]></description>
			<content:encoded><![CDATA[<p>Rounded corners are all the rage at the moment, so you would think that there would be an API on <strong>UIView</strong> to do such a thing. If you looked at all of the <strong>UIView</strong> documentation, you would come to the conclusion that there is not an API to do such a thing, and you would be (kind of) wrong.</p>
<p>Although <strong>UIView</strong> does not allow you round its corners, <strong>CALayer</strong> does, and every <strong>UIView</strong> is backed by a <strong>CALayer</strong>.</p>
<p>To access all of the functionality of <strong>CALayer</strong>, you will need to import QuartzCore into any of header/implementation files that you intend to use <strong>CALayer</strong> in.</p>

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

<p><strong>CALayer</strong> has a lot of APIs available to it, but the property we are interested in is:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@property</span> CGFloat cornerRadius</pre></div></div>

<p>As the property suggests, this allows you to set the <strong>CALayer</strong>&#8216;s corner radius in points:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UIView <span style="color: #002200;">*</span>view <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>frame<span style="color: #002200;">&#93;</span>;
view.layer.cornerRadius <span style="color: #002200;">=</span> <span style="color: #2400d9;">10.0</span>;</pre></div></div>

<p><strong>CALayer</strong> also has properties allowing you to set its border, shadow etc, so all of these can save you a lot of code &#8230; and unwanted images.</p>
]]></content:encoded>
			<wfw:commentRss>http://objcolumnist.com/2010/08/15/rounding-the-corners-of-an-uiview/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Show hidden files in the Finder</title>
		<link>http://objcolumnist.com/2010/01/10/show-hidden-files-in-the-finder/</link>
		<comments>http://objcolumnist.com/2010/01/10/show-hidden-files-in-the-finder/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 14:28:00 +0000</pubDate>
		<dc:creator>Spencer MacDonald</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Quick Tip]]></category>

		<guid isPermaLink="false">http://objcolumnist.com/?p=164</guid>
		<description><![CDATA[Sometimes when you are digging around in the under pinnings of Mac OS X, you need to access folders and files that are normally hidden by the OS. Thankfully there is preference in the Finder for this, which you can turn on and off in the Terminal. The command is: defaults write com.apple.Finder AppleShowAllFiles YES [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes when you are digging around in the under pinnings of Mac OS X, you need to access folders and files that are normally hidden by the OS. Thankfully there is preference in the Finder for this, which you can turn on and off in the Terminal.</p>
<p>The command is:<br />
<code><br />
defaults write com.apple.Finder AppleShowAllFiles YES<br />
</code></p>
<p>The Finder needs to be restarted for this change to take effect. Luckily there is a Terminal command for this too:</p>
<p><code><br />
killall Finder<br />
</code></p>
<p>Once you are done playing around with hidden files, you can stop showing them by replacing YES with NO in the original terminal command.</p>
<p><code><br />
defaults write com.apple.Finder AppleShowAllFiles NO<br />
</code></p>
<p>It is as simple as that, but make sure your don&#8217;t break anything.</p>
]]></content:encoded>
			<wfw:commentRss>http://objcolumnist.com/2010/01/10/show-hidden-files-in-the-finder/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Reopening an application&#8217;s main window by clicking on the Dock Icon</title>
		<link>http://objcolumnist.com/2009/08/09/reopening-an-applications-main-window-by-clicking-the-dock-icon/</link>
		<comments>http://objcolumnist.com/2009/08/09/reopening-an-applications-main-window-by-clicking-the-dock-icon/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 10:57:29 +0000</pubDate>
		<dc:creator>Spencer MacDonald</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Quick Tip]]></category>

		<guid isPermaLink="false">http://objcolumnist.com/?p=128</guid>
		<description><![CDATA[When building Mac applications, Apple usually takes care of most of the default behaviours for you. One thing that Mac applications don&#8217;t do by default is, reopening the applications main window (if it has been closed), when the dock icon is pressed. Although this information is very hard to find in the documentation, but is [...]]]></description>
			<content:encoded><![CDATA[<p>When building Mac applications, Apple usually takes care of most of the default behaviours for you. One thing that Mac applications don&#8217;t do by default is, reopening the applications main window (if it has been closed), when the dock icon is pressed.</p>
<p>Although this information is very hard to find in the documentation, but is actually very easy to. The method you need to find is:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td 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>applicationShouldHandleReopen<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSApplication</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>theApplication hasVisibleWindows<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>flag;</pre></td></tr></table></div>

<p>This is an optional delegate method that your AppDelegate can choose to implement, and is called when the user presses your application&#8217;s dock icon. The bool flags indicates whether the application has any visible windows. To reopen your application&#8217;s main window, you need to have a pointer to it (In the example below assume that it is defined as NSWindow *window; in the header file). If you do have a pointer to then you simple need to implement the code below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;">&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>applicationShouldHandleReopen<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSApplication</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>theApplication hasVisibleWindows<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>flag<span style="color: #002200;">&#123;</span>
&nbsp;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>flag<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: #002200;">&#91;</span>window makeKeyAndOrderFront<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;	
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>;	
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>It is as simple as that.</p>
]]></content:encoded>
			<wfw:commentRss>http://objcolumnist.com/2009/08/09/reopening-an-applications-main-window-by-clicking-the-dock-icon/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Changing the name of an iPhone application</title>
		<link>http://objcolumnist.com/2009/07/04/changing-the-name-of-an-iphone-application/</link>
		<comments>http://objcolumnist.com/2009/07/04/changing-the-name-of-an-iphone-application/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 11:26:10 +0000</pubDate>
		<dc:creator>Spencer MacDonald</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Quick Tip]]></category>

		<guid isPermaLink="false">http://objcolumnist.com/?p=105</guid>
		<description><![CDATA[When you finally come to release your application after months of hard work, your might want to change the name of the application that appears on the iPhone springboard, and if you use it, the settings application. To change the name of an iPhone application is very easy. Simply open the Xcode project, and then [...]]]></description>
			<content:encoded><![CDATA[<p>When you finally come to release your application after months of hard work, your might want to change the name of the application that appears on the iPhone springboard, and if you use it, the settings application.</p>
<p>To change the name of an iPhone application is very easy. Simply open the Xcode project, and then scroll down to the &#8220;Targets&#8221; section, which the the &#8220;Groups &#038; Files&#8221; part of Xcode. Select the application&#8217;s target and &#8220;Get info&#8221; on it using cmd-i or ctrl clicking it, and select &#8220;Get Info&#8221; from the menu.</p>
<p>In the build section of the get info window, you need to change the &#8220;Product Name&#8221; value to whatever you want your application to be called. When you change this value make sure that the configuration pop up menu (at the top of the window) is set to &#8220;All Configurations&#8221;, so it takes effect in all of your builds.</p>
<p>For the change of name to take effect, simply clean your targets and rebuild your application.</p>
]]></content:encoded>
			<wfw:commentRss>http://objcolumnist.com/2009/07/04/changing-the-name-of-an-iphone-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Make your iPhone vibrate</title>
		<link>http://objcolumnist.com/2009/05/23/make-your-iphone-vibrate/</link>
		<comments>http://objcolumnist.com/2009/05/23/make-your-iphone-vibrate/#comments</comments>
		<pubDate>Sat, 23 May 2009 20:27:58 +0000</pubDate>
		<dc:creator>Spencer MacDonald</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Quick Tip]]></category>

		<guid isPermaLink="false">http://objcolumnist.com/?p=56</guid>
		<description><![CDATA[One thing that took me a while to find out, was how to make an iPhone vibrate. In the end I found out that it is in the audio APIs, and it is just the one line of code. AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);]]></description>
			<content:encoded><![CDATA[<p>One thing that took me a while to find out, was how to make an iPhone vibrate. In the end I found out that it is in the audio APIs, and it is just the one line of code.</p>
<p><code><br />
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://objcolumnist.com/2009/05/23/make-your-iphone-vibrate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Categories</title>
		<link>http://objcolumnist.com/2009/05/22/categories/</link>
		<comments>http://objcolumnist.com/2009/05/22/categories/#comments</comments>
		<pubDate>Fri, 22 May 2009 20:27:11 +0000</pubDate>
		<dc:creator>Spencer MacDonald</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Quick Tip]]></category>

		<guid isPermaLink="false">http://objcolumnist.com/?p=46</guid>
		<description><![CDATA[Ever thought &#8220;Oh I wish Apple had included method X for class Y&#8221;, well that is what categories are for. Categories are normally used for 2 things. Extending a class (using methods, not variables !!!) Logically separating a class into different functional areas So lets look at something that is extremely popular at the moment [...]]]></description>
			<content:encoded><![CDATA[<p>Ever thought &#8220;Oh I wish Apple had included method X for class Y&#8221;, well that is what categories are for. </p>
<p>Categories are normally used for 2 things.</p>
<ul>
<li>Extending a class (using methods, not variables !!!)</li>
<li>Logically separating a class into different functional areas</i>
</ul>
<p>So lets look at something that is extremely popular at the moment &#8230;.. Twitter, and in paticular the 140 charachter limit.</p>
<p>Apple (for obvious reasons) don&#8217;t include Twitter related method calls on there string class NSString.</p>
<p>At the moment you would have to write everywhere in you code, something the resembles the following</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>twitterString<span style="color: #002200;">=</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Objective-C rocks, I never want to look at Java again&quot;</span>;
&nbsp;
<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>twitterString<span style="color: #002200;">&#93;</span> length<span style="color: #002200;">&#93;</span>&lt; <span style="color: #2400d9;">141</span><span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
<span style="color: #11740a; font-style: italic;">//Post to twitter</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Now this is good, but what if twitter changed their character limit, you would have to go an edit your code everywhere, where you used this check.<br />
So we are going add a method to the NSString class:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>isUnderTwitterCharachterLimit;</pre></div></div>

<p>This will make are code look like this</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>twitterString<span style="color: #002200;">=</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Objective-C rocks, I never want to look at Java again&quot;</span>;
&nbsp;
<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>twitterString isUnderTwitterCharachterLimit<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
<span style="color: #11740a; font-style: italic;">//Post to twitter</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>You now need an interface and implementation file, Im going to call them NSStringTwitterCategory.h and NSStringTwitterCategory.m</p>
<p>The interface file (NSStringTwitterCategory.h) is extremely small:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">&nbsp;
<span style="color: #6e371a;">#import &lt;Foundation/Foundation.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">&#40;</span>Twitter<span style="color: #002200;">&#41;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>isUnderTwitterCharachterLimit;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Instead of defining a new class in the format:</p>
<p><code><br />
@interface NewClass: SuperClass{</p>
<p>}<br />
</code><br />
You extend an existing class using the format:</p>
<p><code><br />
@interface ClassYourExtending (CategoryName)<br />
</code></p>
<p>You can call the category whatever you want, but obviously you want to make it clear.</p>
<p>You then declare the methods like you always do.</p>
<p>The implementation file (NSStringTwitterCategory.m) is also not very complex:<br />
<code></p>
<p>#import "NSStringTwitterCategory.h"</p>
<p>@implementation NSString (Twitter)</p>
<p>-(BOOL)isUnderTwitterCharachterLimit{</p>
<p>if ( [ [self length] <141])<br />
         return YES;<br />
else<br />
       return NO;<br />
}</p>
<p>@end<br />
</code></p>
<p>Again you extend the class in the same way as you did in the header file:</p>
<p><code><br />
@implementation NSString (Twitter)<br />
</code></p>
<p>And you simple define the method as you normally would, nothing strange or fancy. If you want to use this category you just need to import the header file where you want to use it.</p>
<p>This is obviously a very simple example, but I hope it shows you how to use categories in Objective-C.</p>
]]></content:encoded>
			<wfw:commentRss>http://objcolumnist.com/2009/05/22/categories/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Does a NSString contain a substring ?</title>
		<link>http://objcolumnist.com/2009/04/12/does-a-nsstring-contain-a-substring/</link>
		<comments>http://objcolumnist.com/2009/04/12/does-a-nsstring-contain-a-substring/#comments</comments>
		<pubDate>Sun, 12 Apr 2009 13:14:22 +0000</pubDate>
		<dc:creator>Spencer MacDonald</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Quick Tip]]></category>

		<guid isPermaLink="false">http://objcolumnist.com/?p=36</guid>
		<description><![CDATA[Here is a little tip on how to tell if a string contains another string, using the underused data type NSRange. NSRange gives the starting location and the length of a given value, and is often used with arrays and strings. On this occasion we will use it to find the range of a substring [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a little tip on how to tell if a string contains another string, using the underused data type NSRange.</p>
<p>NSRange gives the starting location and the length of a given value, and is often used with arrays and strings. On this occasion we will use it to find the range of a substring within another string. If the range has a location, it contains the given substring. The following code does just that.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;">&nbsp;
<span style="color: #a61390;">NSRange</span> textRange;
textRange <span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span><span style="color: #a61390;">string</span> rangeOfString<span style="color: #002200;">:</span>substring<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>textRange.location <span style="color: #002200;">!=</span> NSNotFound<span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//Does contain the substring</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Making this a case insensitive compare is also very trivial, and can be done by lowercasing both strings</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;">&nbsp;
<span style="color: #a61390;">NSRange</span> textRange;
textRange <span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #a61390;">string</span> lowercaseString<span style="color: #002200;">&#93;</span> rangeOfString<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>substring lowercaseString<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>textRange.location <span style="color: #002200;">!=</span> NSNotFound<span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//Does contain the substring</span>
&nbsp;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://objcolumnist.com/2009/04/12/does-a-nsstring-contain-a-substring/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

