<?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>Click, Flick, Boom!</title>
	<atom:link href="http://clickflickboom.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://clickflickboom.com</link>
	<description>Chronicles of a Web developer learning Objective C and the iOS SDK</description>
	<lastBuildDate>Mon, 20 Aug 2012 06:13:17 +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>PhotoStack – An iOS class to create a Stack of Images</title>
		<link>http://clickflickboom.com/photostack/</link>
		<comments>http://clickflickboom.com/photostack/#comments</comments>
		<pubDate>Sat, 18 Aug 2012 13:21:47 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[GitHub]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Photos]]></category>
		<category><![CDATA[PhotoStack]]></category>

		<guid isPermaLink="false">http://clickflickboom.com/?p=340</guid>
		<description><![CDATA[<p>I&#8217;ve always liked the way the eBay app for iPad handles multiple photos for a listing. For those that haven&#8217;t seen it, the way it works is that all photos are stacked on top of one another, and the user flicks through the pile. PhotoStack is my attempt to re-create this user interface. Here&#8217;s a [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-343" title="screenshot" src="http://clickflickboom.com/wp-content/uploads/2012/08/screenshot.jpg" alt="" width="500" height="446" /></p>
<p>I&#8217;ve always liked the way the eBay app for iPad handles multiple photos for a listing. For those that haven&#8217;t seen it, the way it works is that all photos are stacked on top of one another, and the user flicks through the pile.</p>
<p>PhotoStack is my attempt to re-create this user interface. Here&#8217;s a video demo of it working:</p>
<p><iframe width="500" height="281" src="http://www.youtube.com/embed/wmpg6nIV3ns?fs=1&#038;feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<h2><span id="more-340"></span>Installation</h2>
<p>First, <a href="https://github.com/tomlongo/PhotoStack">download the source (including example Xcode project) from here</a>, then include PhotoStackView.h, PhotoStackView.m and PhotoBorder.png files into your project.</p>
<p>Include PhotoStackView.h and you&#8217;re ready to go! To create a PhotoStack object, first initialise it as you would with a normal view:</p><pre class="crayon-plain-tag">PhotoStackView *photoStack = [[PhotoStackView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];</pre><p></p>
<h2>Set Up DataSource</h2>
<p>To populate with photos, you&#8217;ll need to set the controller class as a PhotoStackViewDataSource.</p><pre class="crayon-plain-tag">photoStack.dataSource = self;</pre><p>The PhotoStackViewDataSource protocol requires two methods to be implemented. These are modelled off Apple&#8217;s TableView convention so they should be familiar to most developers.</p><pre class="crayon-plain-tag">-(NSUInteger)numberOfPhotosInPhotoStackView:(PhotoStackView *)photoStack;</pre><p>The above should return the number of photos in the PhotoStack view.</p><pre class="crayon-plain-tag">-(UIImage *)photoStackView:(PhotoStackView *)photoStack photoForIndex:(NSUInteger)index;</pre><p>The above should return a UIImage for the provided index.</p>
<h2>Set Up Delegate</h2>
<p>There is also a PhotoStackViewDelegate protocol which can be used like so:</p><pre class="crayon-plain-tag">photoStack.delegate = self;</pre><p>This protocol contains four <em>optional</em> methods.</p><pre class="crayon-plain-tag">-(void)photoStackView:(PhotoStackView *)photoStackView willStartMovingPhotoAtIndex:(NSUInteger)index;</pre><p>Called when the user starts to pan the top photo with their finger.</p><pre class="crayon-plain-tag">-(void)photoStackView:(PhotoStackView *)photoStackView willFlickAwayPhotoAtIndex:(NSUInteger)index;</pre><p>Called when the user flicks the top photo left or right with sufficient velocity to cause it to fly away and go to the bottom of the stack.</p><pre class="crayon-plain-tag">-(void)photoStackView:(PhotoStackView *)photoStackView didRevealPhotoAtIndex:(NSUInteger)index;</pre><p>Called when a new card is revealed at the top of the stack because the previous one was flicked away.</p><pre class="crayon-plain-tag">-(void)photoStackView:(PhotoStackView *)photoStackView didSelectPhotoAtIndex:(NSUInteger)index;</pre><p>Called when the user taps on the top photo of the stack.</p>
<h2>Properties</h2>
<p>A PhotoStackView has a number of useful properties for controlling the appearance of the stack.</p><pre class="crayon-plain-tag">@property (nonatomic, strong) UIImage *borderImage;</pre><p>The image to use for the border (default is white rounded corner, similar to eBay&#8217;s).</p><pre class="crayon-plain-tag">@property BOOL showBorder;</pre><p>Whether or not to show a border at all (default is YES).</p><pre class="crayon-plain-tag">@property float borderWidth;</pre><p>The width of the border (default is 5.0).</p><pre class="crayon-plain-tag">@property float rotationOffset;</pre><p>How many degrees each photo in the stack could be rotated (Default is 4.0). For example, a value of 10.0 will randomly rotate each photo from -10 to +10 degrees.</p><pre class="crayon-plain-tag">@property (nonatomic, strong) UIColor *highlightColor;</pre><p>The overlay colour that appears when the user taps on a photo (Default is black at 0.15 alpha).</p>
<h2>Other Methods</h2>
<p>Just two public methods currently:</p><pre class="crayon-plain-tag">-(void)reloadData;</pre><p>Reloads the data, re-fetching photos from the PhotoStackViewDataSource.</p><pre class="crayon-plain-tag">-(void)goToPhotoAtIndex:(NSUInteger)index;</pre><p>Brings the photo at the specified index to the front.</p>
<h2>Download Source Code and Example Project</h2>
<p><a href="https://github.com/tomlongo/PhotoStack">You can download the source and example project from GitHub here</a>. Enjoy :)</p>
]]></content:encoded>
			<wfw:commentRss>http://clickflickboom.com/photostack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Protocols &amp; Custom Delegates</title>
		<link>http://clickflickboom.com/protocols-custom-delegates/</link>
		<comments>http://clickflickboom.com/protocols-custom-delegates/#comments</comments>
		<pubDate>Thu, 07 Jun 2012 08:53:52 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Diary Entry]]></category>
		<category><![CDATA[@protocol]]></category>
		<category><![CDATA[delegates]]></category>
		<category><![CDATA[UIView]]></category>

		<guid isPermaLink="false">http://clickflickboom.com/?p=317</guid>
		<description><![CDATA[<p>Understanding delegation in iOS vital when creating an app of any complexity, however I found it difficult to find a good, concise explanation of what it is during the early stages of my learning. In this post I&#8217;ll try to explain exactly what it is and provide some steps for creating your own custom delegates. [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p>Understanding delegation in iOS vital when creating an app of any complexity, however I found it difficult to find a good, concise explanation of what it is during the early stages of my learning. In this post I&#8217;ll try to explain exactly what it is and provide some steps for creating your own custom delegates.</p>
<p>This is not intended to be an exhaustive tutorial, just an introduction to the concepts of what delegation is. I found that once I understood exactly what delegation was and why I might want to use it, Googling the answers became much easier.<span id="more-317"></span></p>
<h2>What Are Delegates?</h2>
<p>To understand why delegation is important, you first need to consider the Model View Controller design pattern (I&#8217;ll assume you&#8217;re familiar with it already if not, <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id=473757255">see lecture 1 of Paul Hegarty&#8217;s iOS Development series on iTunes U</a>). The most important rule when it comes to MVC is that each area is responsible for its own domain, that is:</p>
<ul>
<li>The model handles the data</li>
<li>The view handles things that appear on screen</li>
<li>The controller sits between the model and view and passes data from the model to the view</li>
</ul>
<p>Critically, the pathway from the controller to the view should always be one-way – in fact, the view should not even know the controller exists. For example, if you created an iPhone application with a controller and a view, you should be able to swap out the view for an iPad-specific file while still using the same controller. After all, the controller only cares about what data it can get from the model, and how that data should be structured before it is sent over to a view.</p>
<p>Now, on the Web this is an easy concept to maintain because once the page has been sent to the browser it no longer has access to the controller anyway. In software, however, there are often times when the view needs extra information from the controller that it didn&#8217;t need before.</p>
<p>You don&#8217;t want your view directly calling controller methods because this would violate MVC best practices; instead, you should use a delegate.</p>
<h3>Delegate Example</h3>
<p>Take this scene:<br />
<a href="http://clickflickboom.com/wp-content/uploads/2012/06/Screen-Shot-2012-06-07-at-5.03.53-PM.png"><img class="aligncenter size-medium wp-image-319" title="Race Example" src="http://clickflickboom.com/wp-content/uploads/2012/06/Screen-Shot-2012-06-07-at-5.03.53-PM-300x196.png" alt="" width="300" height="196" /></a></p>
<p>To create this scene I&#8217;d need a Track Controller that grabs data about the cars from the Model (position, player name, etc), then the controller would send this info to my Car View. The Car View then draws the cars on the screen based on the information it received.</p>
<p>Cool, but now what happens if one car hits the other? I need to handle the collision and adjust the car&#8217;s damage. This means checking what the car&#8217;s current damage, then adjusting the view to reflect the new info. This requires looking up the database, interpreting the data, and sending updated info to the view.</p>
<p>What you don&#8217;t want to do is have the view itself querying the Model, that is the domain of the controller. Essentially the view needs to ask the controller what it needs to do (or in other words, <em>delegate</em> responsibility for handling this event). The view can then get a response from its delegate for how it should handle the situation, it can update itself without ever having ventured outside its own domain.</p>
<h2>Creating Custom Delegates</h2>
<p>Using the race example above, we would have two files:</p>
<ol>
<li><strong>TrackController</strong><br />
A UIViewController that liaises with the Model and sends info to the view for display.</li>
<li><strong>CarView</strong><br />
A UIView which draws a car on the screen based on information it receives, such as damage and position.</li>
</ol>
<p>What I want to do is set up a delegate so that when this car collides with something, it asks its delegate (in this case, my TrackController) what to do.</p>
<h3>Step 1: Add a Protocol to View</h3>
<p>First thing I need to do is define what methods my view&#8217;s delegate needs to implement. I do this by adding @protocol to the top of my Car.h file:</p><pre class="crayon-plain-tag">#import &amp;lt;UIKit/UIKit.h&amp;gt;

@protocol CarDelegate &amp;lt;NSObject&amp;gt;
@required
-(void)handleCollision;
@end

@interface Car : UIView

@property (weak, nonatomic) id &amp;lt;CarDelegate&amp;gt; delegate;

//Other @properties and method declarations here

@end</pre><p>The protocol above states that anyone who claims to be a CarDelegate is required to implement the method handleCollision. Note that the Car object does <em>not</em> need to implement the handleCollision method itself.</p>
<p>Also notice the @property &#8220;delegate&#8221;; the value of this property will be the delegate that implements the defined protocol (more on that below). Don&#8217;t forget to @synthesize the delegate property as you would any other.</p>
<h3>Step 2: Set Up Your Delegate</h3>
<p>Now that my Car view has a protocol, I can set my TrackController as the delegate. This is done in the TrackController.h file:</p><pre class="crayon-plain-tag">#import &amp;lt;UIKit/UIKit.h&amp;gt;
#import &quot;Car.h&quot;

@interface TrackController : UIViewController &amp;lt;CarDelegate&amp;gt;
-(void)handleCollision;

@property (nonatomic, strong) Car *aCar;
//Other @properties and method declarations go here

@end</pre><p>A few things of note here:</p>
<ul>
<li>Car.h has been included at the top of the file</li>
<li>Added &lt;CarDelegate&gt; to the @interface line. This declares TrackController as conforming to the CarDelegate protocol.</li>
<li>Declared the handleCollision method defined in the protocol</li>
</ul>
<p>Make sure you implement the handleCollision method in the .m file of course.</p><pre class="crayon-plain-tag">-(void)handleCollision {
    //handle collision here
}</pre><p></p>
<h3>Step 3: Link Delegate</h3>
<p>Everything is set up, but we need to link TrackController to Car before it will start working. Remember the &#8220;delegate&#8221; @protocol set up in Step 1? This needs to be set as a pointer back to TrackController. The logical place for this is when the Car object has initialised within the TrackController, for example:</p><pre class="crayon-plain-tag">#import &quot;TrackController.h&quot;

@implementation TrackController

@synthesize aCar = _aCar;

-(void)handleCollision {
    //handle collision here
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.aCar.delegate = self;
}

@end</pre><p>Look at the viewDidLoad method above; note that I&#8217;m setting the value of the delegate property of &#8220;aCar&#8221; to self. That is, &#8220;aCar&#8221; – which is a pointer to Car object – has its delegate method set to TrackController.</p>
<p>You could also set the delegate in aCar&#8217;s setter. In fact, that&#8217;s probably a better place now that I think about it, but whatever this is just a demo :)</p>
<h3>Step 4: Trigger Delegate Method</h3>
<p>Now that TrackController is set as my delegate I can trigger the method from Car.m whenever I need to. For example:</p><pre class="crayon-plain-tag">-(void)checkPositionOfCar {
    if(carIsColliding) {
        [self.delegate handleCollision];
    }
}</pre><p>You can also check to make sure the delegate implements the method before calling it like so:</p><pre class="crayon-plain-tag">if([self.delegate respondsToSelector:@selector(handleCollision)]) {
            [self.delegate handleCollision];
        }</pre><p>Done!</p>
<h2>Download Example Project</h2>
<p>I&#8217;ve created a modified version of the red box project from my <a title="Animating Views" href="http://clickflickboom.com/animating-views/">animation post</a> which uses delegation. <a href="http://clickflickboom.com/wp-content/uploads/2012/06/DelegateExample.zip">You can download the project file here</a>.</p>
<p style="text-align: center;"><a href="http://clickflickboom.com/wp-content/uploads/2012/06/DelegateExample.zip"><img class="aligncenter size-medium wp-image-321" title="Box Project" src="http://clickflickboom.com/wp-content/uploads/2012/06/Screen-Shot-2012-06-07-at-5.58.20-PM-159x300.png" alt="" width="159" height="300" /></a></p>
<p>In the project, when the user clicks the Move Red Box button the box moves within the white square. Once the animation completes, it sends its new coordinates back to the controller.</p>
]]></content:encoded>
			<wfw:commentRss>http://clickflickboom.com/protocols-custom-delegates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Animating Views</title>
		<link>http://clickflickboom.com/animating-views/</link>
		<comments>http://clickflickboom.com/animating-views/#comments</comments>
		<pubDate>Thu, 31 May 2012 00:22:31 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Diary Entry]]></category>
		<category><![CDATA[animateWithDuration]]></category>
		<category><![CDATA[CGGoingMake]]></category>
		<category><![CDATA[CGPoint]]></category>
		<category><![CDATA[UIView]]></category>

		<guid isPermaLink="false">http://clickflickboom.com/?p=305</guid>
		<description><![CDATA[<p>Now that I&#8217;ve popped my App Store cherry, I&#8217;m ready to get serious. I&#8217;ve started working on a project that requires the animation of a UIView. For this post I&#8217;ve created the following scene where the red box moves to a random point within the white box whenever the user clicks the &#8220;Move Red Box&#8221; [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p>Now that I&#8217;ve <a title="The Deep End: What I Learned From My First App Submission" href="http://clickflickboom.com/the-deep-end-what-i-learned-from-my-first-app-submission/">popped my App Store cherry</a>, I&#8217;m ready to get serious. I&#8217;ve started working on a project that requires the animation of a UIView. For this post I&#8217;ve created the following scene where the red box moves to a random point within the white box whenever the user clicks the &#8220;Move Red Box&#8221; button:</p>
<p><img class="aligncenter size-medium wp-image-306" title="redbox" src="http://clickflickboom.com/wp-content/uploads/2012/05/redbox-229x300.png" alt="" width="229" height="300" /></p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/Animation.zip">Download the project here</a> to look at how everything works. The magic happens in the TopView.m file:</p><pre class="crayon-plain-tag">-(void)moveBoxTo:(CGPoint)point {

    CGRect frame = self.box.frame; //where self.box is the Red Box
    frame.origin.x = point.x; // new x coordinate (int)
    frame.origin.y = point.y; // new y coordinate (int)

    [UIView animateWithDuration:1.0
                          delay: 0.0
                        options: UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         self.box.frame = frame; //This is what will animate
                     }
                     completion:^(BOOL finished){
                         //do something on finish
                     }];

}</pre><p>Whenever moveBoxTo is triggered, the x and y coordinates defined in the point parameter are used to reposition it. The parameters are:</p>
<ul>
<li><strong>animateWithDuration</strong><br />
As the name suggests, the duration for the animation.</li>
<li><strong>delay</strong><br />
You can delay the start of the animation (in seconds) here.</li>
<li><strong>options</strong><br />
Here you can define the type of animation, such as easing in or out.  <a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/c/econst/UIViewAnimationOptionCurveEaseInOut">See UIView Class Reference for the options available</a>.</li>
<li><strong>animations</strong><br />
A block which defines what properties the target object should animate. In this case, I&#8217;m animating the frame property.</li>
<li><strong>Completion</strong><br />
Another block which is triggered once the animation completes.</li>
</ul>
<p>Here&#8217;s an example of how you might call the method:</p><pre class="crayon-plain-tag">int x = random() % 300; // random number, max of 300
    int y = random() % 400; // random number, max of 400

    CGPoint point = CGPointMake(x,y); //create the CGPoint to pass along
    [self.box moveBoxTo:point]; // trigger moveBoxTo method</pre><p></p>
<h2>Download Project File</h2>
<p>I&#8217;ve skipped over the finer points to keep things simple. <a href="http://clickflickboom.com/wp-content/uploads/2012/05/Animation.zip">Download the project file here to poke around</a> :)</p>
]]></content:encoded>
			<wfw:commentRss>http://clickflickboom.com/animating-views/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Deep End: What I Learned From My First App Submission</title>
		<link>http://clickflickboom.com/the-deep-end-what-i-learned-from-my-first-app-submission/</link>
		<comments>http://clickflickboom.com/the-deep-end-what-i-learned-from-my-first-app-submission/#comments</comments>
		<pubDate>Fri, 18 May 2012 05:25:36 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Diary Entry]]></category>
		<category><![CDATA[App Store]]></category>
		<category><![CDATA[Core Location]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[MapKit]]></category>
		<category><![CDATA[UITableView]]></category>
		<category><![CDATA[UITableViewCel]]></category>
		<category><![CDATA[Zombies]]></category>

		<guid isPermaLink="false">http://clickflickboom.com/?p=262</guid>
		<description><![CDATA[<p>I haven&#8217;t posted in a while but I have a good excuse! About a week ago I found out about a competition Sensis Australia were holding for developers to create an application that uses their new API. Now, at this point I&#8217;d only been learning iOS development for about a month or so in my [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t posted in a while but I have a good excuse! About a week ago I found out about a competition Sensis Australia were holding for developers to create an application that uses <a href="http://developers.sensis.com.au/">their new API</a>.</p>
<p style="text-align: center;"><a href="http://developers.sensis.com.au/blog/read/SAPI_Bounty"><img class="aligncenter size-large wp-image-269" title="SAPI Competition" src="http://clickflickboom.com/wp-content/uploads/2012/05/BlogHeader-500x203.jpg" alt="" width="500" height="203" /></a></p>
<p>Now, at this point I&#8217;d only been learning iOS development for about a month or so in my free time; I wasn&#8217;t ready for a full blown, public application. Not only that, but in order to get it in the App Store in time I would need to create the app – from start to finish – within a week.</p>
<p>That&#8217;s bonkers&#8230;but, you know, zombies! I can&#8217;t say no to zombies!</p>
<p>And so, after 6 days and about 100 hours of working non-stop – pausing only for Mothers Day on Sunday – I created my first application. I learned more in those 6 days than I had in the entire time I&#8217;d been learning iOS. I&#8217;m glad I did it, and think I&#8217;m ready for round 2 :)<span id="more-262"></span></p>
<h2>Day 1: Concept, Wireframes &amp; Test API Call</h2>
<p>The first day was about planning exactly what I was going to create, and ensure I had the ability to create it. My idea was simple enough:</p>
<blockquote class="alignCentre"><p>When the Zombie Apocolypse comes, do you have a plan? This app will allow you to generate an action plan for what to do should the undead rise, using the Sensis API to find nearby business that can help.</p></blockquote>
<p>For the UI, I was imagining a table view which you could add items to. Tapping on a cell would reveal a detail view including a map and contact details.</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/wires.png"><img class="aligncenter size-large wp-image-276" title="Wireframes" src="http://clickflickboom.com/wp-content/uploads/2012/05/wires-500x247.png" alt="" width="500" height="247" /></a></p>
<p>The next thing was to get the API working within Xcode. <a href="https://github.com/pumptheory/SAPI-Cocoa-SDK">Fortunately there was already a library available for interacting with the API on Github</a>. So I imported the library into my Xcode project and tried to make my first API call.</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-17-at-5.37.03-PM.png"><img class="aligncenter size-medium wp-image-277" title="Errors" src="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-17-at-5.37.03-PM-300x109.png" alt="" width="300" height="109" /></a></p>
<p>Looks like the library isn&#8217;t ARC based. Now, in my short time with Xcode I&#8217;ve come across this a few times; usually it&#8217;s just a matter of removing references to release and retain, however I didn&#8217;t want to start changing code in the library. Digging through the documentation revealed a handy trick, allowing me to set a compiler flag on individual files.</p>
<p>It&#8217;s just a matter of going to Build Phases and setting the compiler flag <code>-fno-objc-arc</code> to any files that aren&#8217;t using ARC.</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/noarc.png"><img class="aligncenter size-large wp-image-278" title="noarc" src="http://clickflickboom.com/wp-content/uploads/2012/05/noarc-500x258.png" alt="" width="500" height="258" /></a></p>
<p>Once that was done, I had liftoff!</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/Asf5GHeCQAAE4AU.jpg-large.jpeg"><img class="aligncenter size-medium wp-image-279" title="Asf5GHeCQAAE4AU.jpg-large" src="http://clickflickboom.com/wp-content/uploads/2012/05/Asf5GHeCQAAE4AU.jpg-large-e1337243339983-300x161.jpg" alt="" width="300" height="161" /></a></p>
<h2>Day 2: Custom Table Views</h2>
<p>I wanted the table views to look customised rather than the stock iOS designs. Eventually I figured it out, but found it to be quite fiddly. Here&#8217;s the final version:</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-18-at-12.16.18-PM.png"><img class="aligncenter size-medium wp-image-283" title="Table View" src="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-18-at-12.16.18-PM-300x142.png" alt="" width="300" height="142" /></a></p>
<p>It&#8217;s something I need to do a proper tutorial post on, but for now I&#8217;ll share the broad strokes for where to look. The general steps for creating a custom table view are:</p>
<ul>
<li>In your storyboard, add a Master Table View Controller and make sure the type is set to Custom, and the style is either Plain or Grouped (I choose grouped).</li>
<li>In your prototype cell, manually add whatever elements you want to appear inside each cell (labels, UIViews, etc). This can be done simply by dropping them into the prototype cell.</li>
<li>Create a custom subclass for  UITableView and UITableViewCell, then assign those subclasses to your Table View and Table Cell respectively.</li>
<li>Create IBOutlets to connect your storyboard objects to your custom UITableViewCell class<br />
<a href="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-18-at-12.29.51-PM.png"><img class="aligncenter size-large wp-image-287" title="Connecting To Custom Cell Class" src="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-18-at-12.29.51-PM-500x59.png" alt="" width="500" height="59" /></a></li>
<li>Now in your Table View Controller, include the custom cell class, and edit your tableView:cellForRowAtIndexPath: method to handle your new class, for example:<br />
<pre class="crayon-plain-tag">- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @&quot;MyCell&quot;;

    MyCustomCellView *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // here would be where you gather data for this
    // cell, but for demo purposes I'll hard code
    // the label and image values:

    cell.myLabel = @&quot;Text for your custom label&quot;;
    cell.myImage = [UIImage imageNamed:@&quot;myImage&quot;];

    return cell;
}</pre>
</li>
<li>Likewise, you can customise the look of the table itself by editing the drawRect: method within your custom UITableView class, for example:<br />
<pre class="crayon-plain-tag">- (void)drawRect:(CGRect)rect {

    UIImage *backgroundImage = [UIImage imageNamed:@&quot;Background&quot;];
    [backgroundImage drawAsPatternInRect:rect];

    [self setSeparatorColor:[UIColor clearColor]];
    [self setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self setSeparatorColor:[ColourHelper colorWithHexString:@&quot;910000&quot;]];    

}</pre>
</li>
</ul>
<p>That is obviously a super abridged tutorial, but I promise to write up something more substantial a little later!</p>
<h2>Day 3: Core Location &amp; MapKit</h2>
<p>Core Location and MapKit are also worthy of an entire post and took hours of research and experimentation to get right. I&#8217;ll leave them for a separate post when I can explain them properly, but I have a handy bit of code for those working with Core Location. To get the user&#8217;s current location you&#8217;ll need to do the following:</p>
<ul>
<li>Include the CoreLocation framework in your project.</li>
<li>In your controller, include core location in your header<br />
<pre class="crayon-plain-tag">#import &amp;lt;CoreLocation/CoreLocation.h&amp;gt;</pre>
</li>
<li>Also make sure you set your controller as a CLLocationManagerDelegate<br />
<pre class="crayon-plain-tag">@interface MyController : UITableViewController &amp;lt;CLLocationManagerDelegate&amp;gt;

@property (strong, nonatomic) CLLocationManager *locationManager;
// don't forget to @synthesize the property!</pre>
</li>
<li>Once set up, if you want to find the user&#8217;s location you can trigger the location manager&#8217;s startUpdatingLocation method like so:<br />
<pre class="crayon-plain-tag">self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
    self.locationManager.purpose = @&quot;Explanation of why you need the user's location&quot;;
    [self.locationManager startUpdatingLocation];</pre>
</li>
<li>Once location has been updated, this will trigger your delegate&#8217;s locationManager:didUpdateToLocation:fromLocation method:<br />
<pre class="crayon-plain-tag">- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation {

    //stop updating once we have an accurite location
    if(newLocation.horizontalAccuracy &amp;lt;= 100.0f) { 

        [self.locationManager stopUpdatingLocation]; 

            //do something with newLocation here
            NSLog(@&quot;Latitude is %d&quot;, newLocation.coordinate.latitude);
            NSLog(@&quot;Longitude is %d&quot;, newLocation.coordinate.longitude);

    }

}</pre>
</li>
</ul>
<div>It&#8217;s also worth adding a locationManager:didFailWithError: method to handle cases when the user&#8217;s location can&#8217;t be found, or they have turned off location services.</div>
<div>
<pre class="crayon-plain-tag">- (void)locationManager:(CLLocationManager *)manager
       didFailWithError:(NSError *)error {

    //No location services? Show alert to enter postcode manually
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@&quot;Enter a Postcode&quot; message:@&quot;You can also enable location services in your settings.&quot; delegate:self cancelButtonTitle:@&quot;Done&quot; otherButtonTitles:@&quot;Cancel&quot;,nil];
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    alert.delegate = self;
    [alert show];

}</pre>
</div>
<h2>Day 4: Mothers Day &amp; Icons</h2>
<p>Mother&#8217;s day is all about gifts and over-eating, so I didn&#8217;t get a lot of time in Xcode. I did, however, manage to get all the icons done!</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/icons.png"><img class="aligncenter size-large wp-image-290" title="icons" src="http://clickflickboom.com/wp-content/uploads/2012/05/icons-500x321.png" alt="" width="500" height="321" /></a></p>
<h2>Day 5: Cutting Features &amp; Testing</h2>
<p>By day 5, it was pretty clear I wasn&#8217;t going to be able to implement all the features I wanted in time. I wanted the user to be able to compile their own list, but I ended up just making the survival plan pre-generated. I also wanted to dynamically calculate the user&#8217;s chances of survival based on how close each tactical location was to them, but again I needed to cut it if I had any chance to getting the app through the approval process in time.</p>
<p>So I spent all night testing what I had, squashing bugs, adding a help screen, and so on (it&#8217;s funny how the last %10 of development always seems to take the longest). By sunrise I had an app ready for submission!</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/app-gif.gif"><img class="aligncenter size-full wp-image-291" title="App Screens" src="http://clickflickboom.com/wp-content/uploads/2012/05/app-gif.gif" alt="" width="250" height="477" /></a></p>
<h2>Day 6: App Store Submission</h2>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/icon.png"><img class="alignright size-thumbnail wp-image-294" title="icon" src="http://clickflickboom.com/wp-content/uploads/2012/05/icon-150x150.png" alt="" width="150" height="150" /></a>I had everything lined up, I even had a spiffy logo ready to go. I&#8217;d never submitted anything to the app store before but the first part made it seem pretty easy. Here&#8217;s how it works:</p>
<ol>
<li>Go to <a href="http://itunesconnect.apple.com">itunesconnect.apple.com</a></li>
<li>Select Manage Your Applications</li>
<li>Select Add New App and follow instructions</li>
</ol>
<div>This allows you to enter the various information iTunes needs for the App Store listing. Once that&#8217;s done you can head over to Xcode and create the binary. This is done by  choosing Archive from the Product menu.</div>
<div>If all goes well you will be walked through the final steps to submit for approval, but instead I got this:</div>
<p></p><pre class="crayon-plain-tag">Application failed codesign verification.The signature was invalid, contains disallowed entitlements, or it was not signed with an iPhone Distribution Certificate.</pre><p>After some hair pulling (and some help from a work colleague) it turned out I&#8217;m an idiot and never set up a Distribution Certificate. In order to create an archive you need to do the following first:</p>
<ol>
<li>Create a Distribution Certificate from the Developer Centre</li>
<li>In your Project settings, select the distribution certificate for the Code Signing Identity&#8217;s Release setting<br />
<a href="http://clickflickboom.com/wp-content/uploads/2012/05/settings.gif"><img class="aligncenter size-large wp-image-292" title="settings" src="http://clickflickboom.com/wp-content/uploads/2012/05/settings-500x94.gif" alt="" width="500" height="94" /></a></li>
<li>Next go to Product &gt; Edit Scheme and set the Build Configuration drop down to Release.</li>
<li>Go to Product &gt; Archive and cross your fingers!</li>
</ol>
<p>Now, it should be said that even if everything is correct and in place that still doesn&#8217;t guarantee you&#8217;ll have a binary. I&#8217;ve heard horror stories from a bunch of devs about infuriating problems creating a binary; some of whom ended up having to create a fresh Xcode project and re-add everything by hand.</p>
<p>It&#8217;s a surprisingly unintuitive and error-prone system from a company that is known for its superior user experience. Let&#8217;s hope it gets ironed out in the future!</p>
<h2>Closing Comments</h2>
<p>Creating an iOS app is 6 days when I&#8217;m still learning the basics of Objective C was a stressful experience to say the least, but I&#8217;m really glad I did it. Learning abstract concepts and creating test applications is one thing, but working towards a clear goal and creating a real product really fast-tracked my development. Regardless of the outcome of the competition itself, this has been a hugely rewarding experience and an important milestone in my growth as an iOS developer.</p>
<p>If there were a zombie apocalypse right now, they&#8217;d all be coming for me, because my brain is overflowing with juicy new knowledge. Fortunately for me, there&#8217;s now an app for that ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://clickflickboom.com/the-deep-end-what-i-learned-from-my-first-app-submission/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Drawing in Obj-C: Lines and Circles</title>
		<link>http://clickflickboom.com/drawing-in-objective-c-lines-and-circles/</link>
		<comments>http://clickflickboom.com/drawing-in-objective-c-lines-and-circles/#comments</comments>
		<pubDate>Tue, 08 May 2012 23:00:19 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Diary Entry]]></category>
		<category><![CDATA[CGContext]]></category>
		<category><![CDATA[CGContextDrawPath]]></category>
		<category><![CDATA[CGRect]]></category>
		<category><![CDATA[Drawing]]></category>
		<category><![CDATA[drawRect]]></category>

		<guid isPermaLink="false">http://clickflickboom.com/?p=226</guid>
		<description><![CDATA[<p>In a previous post I showed an example of creating a custom view in which I drew a triangle on screen. I thought I&#8217;d spend a bit of time taking a closer look at the code and demonstrate how to draw simple shapes in Objective-C. Example 1: Lines The following will draw a triangle in [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p>In a previous post I showed an example of <a title="Custom Sub Views" href="http://clickflickboom.com/custom-sub-views/">creating a custom view</a> in which I drew a triangle on screen. I thought I&#8217;d spend a bit of time taking a closer look at the code and demonstrate how to draw simple shapes in Objective-C.</p>
<h2>Example 1: Lines</h2>
<p>The following will draw a triangle in the view with green fill and a red stroke. I&#8217;ve added a bunch of comments to each line to make it clear what is happening.<span id="more-226"></span></p><pre class="crayon-plain-tag">- (void)drawRect:(CGRect)rect
{

    // Get the current graphics context
    // (ie. where the drawing should appear)
	CGContextRef context = UIGraphicsGetCurrentContext();

	//Begin the path
	CGContextBeginPath(context);

	// Starting Point
	CGContextMoveToPoint(context, 150,0);

    // Draw a diagonal line starting ay 150, 0 and ending at x300,y300
	CGContextAddLineToPoint(context, 300, 300);

    // Create a straight horizontal line from the end of the last point, over to x0, y300
	CGContextAddLineToPoint(context, 0, 300);

	// Close the path
    // Closing the path will extending a line from
    // x0, y300 back up to the starting point of 150, 0
	CGContextClosePath(context);

	// Set line width
	CGContextSetLineWidth(context, 2.0);	

	// Set colour using RGB intensity values
    // 1.0 = 100% red, green or blue
    // the last value is alpha
    CGContextSetRGBFillColor(context, 0.0, 1.0, 0.0, 1.0); //green
    CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0); //red

	//Draw on the screen
	CGContextDrawPath(context, kCGPathFillStroke);

}</pre><p>The above will draw something like below:</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-6.48.51-PM.png"><img class="aligncenter size-large wp-image-207" title="Triangle" src="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-6.48.51-PM-266x500.png" alt="" width="266" height="500" /></a></p>
<h2>Example 2: Circles</h2>
<p>Next I&#8217;ll draw a red circle. Again I&#8217;ve added some comments for each line.</p><pre class="crayon-plain-tag">- (void)drawRect:(CGRect)rect
{

    // Get the current graphics context
    // (ie. where the drawing should appear)
	CGContextRef context = UIGraphicsGetCurrentContext();

	// Set the width of the line
	CGContextSetLineWidth(context, 2.0);

    //Make the circle
    // 150 = x coordinate
    // 150 = y coordinate
    // 100 = radius of circle
    // 0   = starting angle
    // 2*M_PI = end angle
    // YES = draw clockwise
    CGContextBeginPath(context);
    CGContextAddArc(context, 150, 150, 100, 0, 2*M_PI, YES);
    CGContextClosePath(context); 

	// Set colour using RGB intensity values
    // 1.0 = 100% red, green or blue
    // the last value is alpha
    CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1.0); //blue
    CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0); //red

    // Note: If I wanted to only stroke the path, use:
    // CGContextDrawPath(context, kCGPathStroke);
    // or to only fill it, use:
    // CGContextDrawPath(context, kCGPathFill);

    //Fill/Stroke the path
	CGContextDrawPath(context, kCGPathFillStroke);

}</pre><p>The above will produce:</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-08-at-10.42.39-PM.png"><img class="aligncenter size-large wp-image-233" title="Circle" src="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-08-at-10.42.39-PM-266x500.png" alt="" width="266" height="500" /></a></p>
<h2>Using Convenience Methods for Drawing</h2>
<p>Say I want to make 3 circles on the screen, each of them with a slightly smaller radius. Well, I could simply copy and paste the code for making a circle 3 times, but it would be better if I could write a single drawCircle: method that will make one for me 3 times.</p>
<p>In my drawRect: I would do something like this:</p><pre class="crayon-plain-tag">- (void)drawRect:(CGRect)rect
{

    // Get the current graphics context
    CGContextRef context = UIGraphicsGetCurrentContext();

    // Clear whatever is currently displayng (optional)
    CGContextClearRect(context, rect);

    [self drawCircleInContext:context withRadius:90];
    [self drawCircleInContext:context withRadius:60];
    [self drawCircleInContext:context withRadius:30];

}</pre><p>Note I&#8217;m grabbing the current context first before calling the circle drawing method with:</p><pre class="crayon-plain-tag">CGContextRef context = UIGraphicsGetCurrentContext();</pre><p>This is important and must be called within drawRect:. Then, I am calling a new method three times, each with a slightly smaller radius:</p><pre class="crayon-plain-tag">[self drawCircleInContext:context withRadius:90];
    [self drawCircleInContext:context withRadius:60];
    [self drawCircleInContext:context withRadius:30];</pre><p>The drawCircleInContext:withRadius: method would look something like this:</p><pre class="crayon-plain-tag">-(void)drawCircleInContext:(CGContextRef)context withRadius:(int)radius {

    // always add at start to make sure
    // specified context context is the current one
    UIGraphicsPushContext(context);

    // DRAW CIRCLE
    // Note: This code will draw the circle and
    //      is the same as before. The only difference
    //      is that I've used the radius int within
    //      CGContextAddArc
	CGContextSetLineWidth(context, 2.0);
    CGContextBeginPath(context);
    CGContextAddArc(context, 150, 150, radius, 0, 2*M_PI, YES);
    CGContextClosePath(context); 

    CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1.0); //blue
    CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0); //red

	CGContextDrawPath(context, kCGPathFillStroke);
    // END DRAW CIRCLE

    // Eemove current context (defined at top of method)
    // from the stack, restoring it to whatever it was before
    UIGraphicsPopContext();

}</pre><p>The bulk of the code will be the same as before, but at the top of the method you&#8217;ll want to add:</p><pre class="crayon-plain-tag">UIGraphicsPushContext(context);</pre><p>This will ensure the context you&#8217;re using is the current one. Then at the bottom of the method (after drawing the circle) you should add:</p><pre class="crayon-plain-tag">UIGraphicsPopContext();</pre><p>This will remove the current context from the stack and restore it to what it was before.</p>
<p>If all went well, you should end up with this:</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-08-at-10.45.55-PM.png"><img class="aligncenter size-large wp-image-234" title="Screen Shot 2012-05-08 at 10.45.55 PM" src="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-08-at-10.45.55-PM-266x500.png" alt="" width="266" height="500" /></a></p>
<h2>Re-Drawing</h2>
<p>I mentioned this in my post about <a title="Custom Sub Views" href="http://clickflickboom.com/custom-sub-views/">Custom Sub Views</a>, but it&#8217;s worth repeating. If you want to change the appearance of your drawing, it might seem logical to call drawRect: from your master view or controller in order to re-draw.</p>
<p><em>Don&#8217;t do it!</em></p>
<p>You should <em>never</em> call drawRect: directly. Instead you should use setNeedsDisplay, like so:</p><pre class="crayon-plain-tag">[self.myCanvas setNeedsDisplay];</pre><p>Assuming self.myCanvas is your UIView that does the drawing, the above line lets the system know that you want to redraw the myCanvas view (you could also call setNeedsDislay within the UIView class itself, of course). As soon as it is ready the view will be updated.</p>
<p>Here&#8217;s an example of how you might trigger this from a view controller:</p><pre class="crayon-plain-tag">- (IBAction)updateCanvas:(id)sender {
    [self.myCanvas setNeedsDisplay];
}</pre><p></p>
<h2>Download Project File</h2>
<p>In case it helps I&#8217;ve made the Xcode project fie available to download below. The app produces either a triangle or circle depending on which button you tap.</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/ShapesApp.zip">Download ShapesApp.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://clickflickboom.com/drawing-in-objective-c-lines-and-circles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Sub Views</title>
		<link>http://clickflickboom.com/custom-sub-views/</link>
		<comments>http://clickflickboom.com/custom-sub-views/#comments</comments>
		<pubDate>Mon, 07 May 2012 00:00:10 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Diary Entry]]></category>
		<category><![CDATA[Drawing]]></category>
		<category><![CDATA[drawRect]]></category>
		<category><![CDATA[IBAction]]></category>
		<category><![CDATA[Opacity]]></category>
		<category><![CDATA[setNeedsDisplay]]></category>
		<category><![CDATA[Storyboard]]></category>
		<category><![CDATA[UIView]]></category>
		<category><![CDATA[Visibility]]></category>

		<guid isPermaLink="false">http://clickflickboom.com/?p=196</guid>
		<description><![CDATA[<p>Placing and drawing UIView objects using the Object Library works a lot of the time, but there are instances where you&#8217;ll need to create your own custom views. A sub view is just a UIView object placed within a parent view. They can be created through the GUI by dragging out an object such as [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p>Placing and drawing UIView objects using the Object Library works a lot of the time, but there are instances where you&#8217;ll need to create your own custom views. A sub view is just a UIView object placed within a parent view. They can be created through the GUI by dragging out an object such as a button or label, or programatically.</p>
<p>There are two common reasons why you&#8217;d want to create a custom sub view:</p>
<ol>
<li>You want create a custom drawing on the screen; or</li>
<li>You want to handle touch events in a way different from the defaults</li>
</ol>
<div>I&#8217;m creating this using a new, single-view application project.<span id="more-196"></span></div>
<h2>Create Custom UIView Subclass</h2>
<p>With your project open, create a new file by going to File &gt; New &gt; New File.. (or press the + button at the bottom-left of the Project Navigator). Choose Objective-C Class:</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-5.53.53-PM.png"><img class="aligncenter size-large wp-image-197" title="New File" src="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-5.53.53-PM-500x335.png" alt="" width="500" height="335" /></a></p>
<p>Then enter a name for the custom view, making sure you choose UIView from the subclass dropdown:</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-5.55.41-PM.png"><img class="aligncenter size-large wp-image-198" title="New File Step 2" src="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-5.55.41-PM-500x335.png" alt="" width="500" height="335" /></a></p>
<p>Your new class&#8217;s implementation file will look something like this:</p><pre class="crayon-plain-tag">#import &quot;MyCanvas.h&quot;

@implementation MyCanvas

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end</pre><p>Note the drawRect: method is commented out by default. You should leave this commented out unless you plan on doing some custom drawing. In this case, I do want to draw a custom shape, so I&#8217;ll un-comment it and add the following (I&#8217;ll explain more about drawing in a later post):</p><pre class="crayon-plain-tag">- (void)drawRect:(CGRect)rect
{

	CGContextRef context = UIGraphicsGetCurrentContext();
	CGContextBeginPath(context);
	CGContextMoveToPoint(context, 150,0);
	CGContextAddLineToPoint(context, 300, 300);
	CGContextAddLineToPoint(context, 0, 300);
	CGContextClosePath(context);
	CGContextSetLineWidth(context, 2.0);	

	[[UIColor greenColor] setFill];
	[[UIColor redColor] setStroke];

	CGContextDrawPath(context, kCGPathFillStroke);

}</pre><p></p>
<h2>Adding Custom View Using Storyboard</h2>
<p>Now that I&#8217;ve created the view class, I need to add it to the screen. On the storyboard, drag out a generic View from the Object Library.</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/drag-cropped.png"><img class="aligncenter size-large wp-image-199" title="Dragging View onto Storyboard" src="http://clickflickboom.com/wp-content/uploads/2012/05/drag-cropped-500x342.png" alt="" width="500" height="342" /></a></p>
<p>You can make the view as large or as small as you want by dragging out the handles or setting values on the right. Once placed, select the view and set its class to the one created earlier.</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-6.11.06-PM.png"><img class="aligncenter size-full wp-image-200" title="Custom Class" src="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-6.11.06-PM.png" alt="" width="261" height="194" /></a></p>
<p>Now, once the app is run and the view loads, drawRect: will be triggered and everything that happens within that method will be run. In this case, a triangle will be drawn. Boom!</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-6.15.09-PM.png"><img class="aligncenter size-medium wp-image-201" title="Custom View Simulation" src="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-6.15.09-PM-159x300.png" alt="" width="159" height="300" /></a></p>
<p>If you need to control your custom view in some way, you can create an IBOutlet for it in your controller just like any other object <a title="IBOutlet and IBAction" href="http://clickflickboom.com/iboutlet-and-ibaction/">as described here</a>.</p>
<h2>Adding Custom View Programatically</h2>
<p>There may be times when you want to create a sub view programatically. For example, say I wanted to make my triangle view appear on the click of a button.</p>
<p>To achieve that, let&#8217;s first delete the view object from the storyboard so that now my screen is completely empty.</p>
<p>First, import your custom UIView subclass to the header file of your View Controller. This ensures the Controller knows about your custom view so you can add an instance of it.</p>
<p><img class="aligncenter size-full wp-image-205" title="Import" src="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-6.36.03-PM.png" alt="" width="202" height="40" /></p>
<p>Then, add a new property, pointing to the new class, here&#8217;s what the header file looks like now:</p><pre class="crayon-plain-tag">#import &amp;lt;UIKit/UIKit.h&amp;gt;
#import &quot;MyCanvas.h&quot;

@interface DemoAppViewController : UIViewController
@property (strong, nonatomic) MyCanvas *myCanvas;
@end</pre><p>Don&#8217;t forget to synthesize the property in the implementation file:</p><pre class="crayon-plain-tag">@synthesize myCanvas = _myCanvas;</pre><p>Next, add a button object on the screen and <a title="IBOutlet and IBAction" href="http://clickflickboom.com/iboutlet-and-ibaction/">setup an IBAction for the button in your View Controller as described in a previous post</a>.  You should end up with something similar to this:</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/IBAction.png"><img class="aligncenter size-large wp-image-203" title="IBAction" src="http://clickflickboom.com/wp-content/uploads/2012/05/IBAction-500x345.png" alt="" width="500" height="345" /></a></p>
<p>Now, within this IBAction you&#8217;ll need to create a sub class, using the custom view we&#8217;ve created.</p><pre class="crayon-plain-tag">- (IBAction)tappedMakeTriangle:(id)sender {
    //make the triangle!
	CGRect viewRect = CGRectMake(10,10,300,300);
	self.myCanvas = [[MyCanvas alloc] initWithFrame:viewRect];
	[self.view addSubview:self.myCanvas];
}</pre><p>Here&#8217;s an explanation of what&#8217;s happening above:</p>
<ul>
<li>Line 3: Make a CGRect that is used on the next line. The first two values (10,10) are for the x and y position within the parent view; the second two values (300,300) are the width and height of the frame.</li>
<li>Line 4: Initialise the MyCanvas view object. The CGRect values defined above will be used to define the size and position of the frame.</li>
<li>Line 5: Add the custom subview to the controller&#8217;s view.</li>
</ul>
<p>If all went well, as soon as the user taps the button, a triangle should appear!</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-6.48.51-PM.png"><img class="aligncenter size-medium wp-image-207" title="Triangle" src="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-6.48.51-PM-159x300.png" alt="" width="159" height="300" /></a></p>
<h2>Opacity and Visibility</h2>
<p>If you intend on playing with the view&#8217;s opacity, you&#8217;ll need to set your view&#8217;s &#8220;opaque&#8221; property to NO. For example:</p><pre class="crayon-plain-tag">self.myCanvas.opaque = NO;</pre><p>By default, this property is set to YES, which means that it is assumed you will never change the opacity. This is for performance reasons.</p>
<p>Another property you may want to change is the visibility. If you want to hide your view, you can do so with the hidden property, e.g.:</p><pre class="crayon-plain-tag">self.myCanvas.hidden = YES;</pre><p>Note that when hidden a view will also not handle events.</p>
<h2>Redrawing The View</h2>
<p>As you saw above, the drawRect: method is responsible for re-drawing your view. However, you should <em>never</em> call drawRect: directly. Instead you should use setNeedsDisplay, like so:</p><pre class="crayon-plain-tag">[self.myCanvas setNeedsDisplay];</pre><p>The above line lets the system know that you want to redraw the myCanvas view. As soon as it is ready (most likely instantly) the view will be updated.</p>
<h2>Download Project File</h2>
<p>In case it helps, I&#8217;ve uploaded the Xcode project file below:</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/DemoApp.zip">DemoApp.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://clickflickboom.com/custom-sub-views/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IBOutlet and IBAction</title>
		<link>http://clickflickboom.com/iboutlet-and-ibaction/</link>
		<comments>http://clickflickboom.com/iboutlet-and-ibaction/#comments</comments>
		<pubDate>Sun, 06 May 2012 05:10:18 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Diary Entry]]></category>
		<category><![CDATA[IBAction]]></category>
		<category><![CDATA[IBOutlet]]></category>
		<category><![CDATA[Storyboard]]></category>
		<category><![CDATA[UIView]]></category>
		<category><![CDATA[UIViewController]]></category>

		<guid isPermaLink="false">http://clickflickboom.com/?p=153</guid>
		<description><![CDATA[<p>Storyboards make it really easy to arrange objects in a view, but you&#8217;ll also need a way to control those objects and handle events in your Controller. As a web developer, this usually means either setting up JavaScript triggers or refreshing the page; in iOS development it means using IBOutlets and IBActions. In this post [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p>Storyboards make it really easy to arrange objects in a view, but you&#8217;ll also need a way to control those objects and handle events in your Controller. As a web developer, this usually means either setting up JavaScript triggers or refreshing the page; in iOS development it means using IBOutlets and IBActions.</p>
<p>In this post I&#8217;ll outline how to connect view objects to your video controllers using IBOutlet and IBAction. <span id="more-153"></span></p>
<h2>Adding a Text Field</h2>
<p>Adding a text field to a view is done by selecting the storyboard and making sure the right sidebar is showing.</p>
<p><a href="http://clickflickboom.com/iboutlet-and-ibaction/toolbar/" rel="attachment wp-att-154"><img class="aligncenter size-full wp-image-154" title="toolbar" src="http://clickflickboom.com/wp-content/uploads/2012/05/toolbar.png" alt="" width="206" height="54" /></a></p>
<p>Selecting the above button will display the right sidebar. Select the File Inspector <img class="alignnone size-full wp-image-155" title="File Inspector" src="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-1.59.05-PM.png" alt="" width="39" height="25" /> and display the Object Library <img class="alignnone size-full wp-image-156" title="Object Library" src="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-1.59.48-PM.png" alt="" width="38" height="27" />, then find the Text Field object. Drag this object into your view.</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/1-text-field-cropped.png"><img class="aligncenter size-large wp-image-159" title="Text Field" src="http://clickflickboom.com/wp-content/uploads/2012/05/1-text-field-cropped-500x346.png" alt="" width="500" height="346" /></a></p>
<p>Once added, you can move and resize it as necessary.</p>
<h2>Add Text Field to View Controller as a Property</h2>
<p>In order to control this text field in the Controller, it needs to be added as a property. First, make sure your view is controlled by a custom subclass of UIViewController. You can check this by selecting the view controller in your storyboard (should outline entire view frame with blue), then check your Identity Inspector.</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/custom-class.png"><img class="aligncenter size-large wp-image-164" title="custom class" src="http://clickflickboom.com/wp-content/uploads/2012/05/custom-class-500x87.png" alt="" width="500" height="87" /></a></p>
<p>If you don&#8217;t have a custom class, create a new UIViewController subclass by going to File &gt; New &gt; New File&#8230; and choosing the appropriate type. Once created, you should be able to see your new custom class in the Custom Class drop down pictured above.</p>
<p>Select the Editor toolbar option <img class="alignnone size-full wp-image-165" title="Editor" src="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-2.11.28-PM.png" alt="" width="90" height="28" /> so you can see both your view and View Controller on screen at the same time. Make sure your right-side view is showing the View Controller&#8217;s .h file. If it isn&#8217;t, you can select it by choosing the appropriate file at the top:</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-2.37.06-PM.png"><img class="aligncenter size-medium wp-image-179" title="Selecting .h file" src="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-2.37.06-PM-300x35.png" alt="" width="300" height="35" /></a></p>
<p>Now, while holding down the Control key, click and drag the text field into your View Controller.</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/2-drag-outlet-cropped.png"><img class="aligncenter size-large wp-image-166" title="Dragging Outlet" src="http://clickflickboom.com/wp-content/uploads/2012/05/2-drag-outlet-cropped-500x128.png" alt="" width="500" height="128" /></a></p>
<p>&nbsp;</p>
<p>This will popup with a few options, one of which is a Name. Give the outlet a name which you will use to refer to the text box in the controller.</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/popup.png"><img class="aligncenter size-large wp-image-167" title="Outlet Popup" src="http://clickflickboom.com/wp-content/uploads/2012/05/popup-500x124.png" alt="" width="500" height="124" /></a></p>
<p>You should now have a new @property in in your View Controller&#8217;s header file, and a @synthesize in the implementation file, allowing you to set and get properties for the text field.</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/outlet.png"><img class="aligncenter size-full wp-image-168" title="outlet" src="http://clickflickboom.com/wp-content/uploads/2012/05/outlet.png" alt="" width="416" height="90" /></a></p>
<h2>Adding a Button</h2>
<p>Adding a button is done in the same way to the text field.</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/3-drag-button-cropped.png"><img class="aligncenter size-large wp-image-169" title="Dragging Button" src="http://clickflickboom.com/wp-content/uploads/2012/05/3-drag-button-cropped-500x196.png" alt="" width="500" height="196" /></a></p>
<p>You can rename the label on the button by double clicking it.</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/edit-button.png"><img class="aligncenter size-full wp-image-170" title="Edit button label" src="http://clickflickboom.com/wp-content/uploads/2012/05/edit-button.png" alt="" width="144" height="69" /></a></p>
<h2>Connect Button to Controller</h2>
<p>Now make sure the right half of the screen is showing your View Controllers implementation file (.m) rather than header file, then Control-drag the button in the same way you did the text field.</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/5-drag-action-cropped.png"><img class="aligncenter size-large wp-image-171" title="Dragging button into implementation file" src="http://clickflickboom.com/wp-content/uploads/2012/05/5-drag-action-cropped-500x140.png" alt="" width="500" height="140" /></a></p>
<p>Once you do this, you&#8217;ll get another popup where your an give the action a name.</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/popup-2.png"><img class="aligncenter size-medium wp-image-172" title="Action Popup" src="http://clickflickboom.com/wp-content/uploads/2012/05/popup-2-300x96.png" alt="" width="300" height="96" /></a></p>
<p>After you click Connect, a link will be made between your View and Controller. You can do whatever you want within this IBAction method, which will be fired whenever the user taps on the button.</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/method.png"><img class="aligncenter size-medium wp-image-173" title="IBAction Method" src="http://clickflickboom.com/wp-content/uploads/2012/05/method-300x55.png" alt="" width="300" height="55" /></a></p>
<h2>Controlling Text Field When Button is Pressed</h2>
<p>Next, we want to add some text to the text field whenever the user taps the button. This is as simple as adding a line within the IBAction you just created.</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/edit-text.png"><img class="aligncenter size-medium wp-image-174" title="edit text" src="http://clickflickboom.com/wp-content/uploads/2012/05/edit-text-300x56.png" alt="" width="300" height="56" /></a></p>
<p>Because the text field has been set as a property of the Controller, all that needs to be done is to set the &#8220;text&#8221; property of myTextField to be whatever value we want. Placing this within the IBAction method means this will only happen if the user taps the &#8220;Press Me&#8221; button.</p>
<p><a href="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-1.46.26-PM.png"><img class="aligncenter size-medium wp-image-182" title="App Preview" src="http://clickflickboom.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-06-at-1.46.26-PM-159x300.png" alt="" width="159" height="300" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://clickflickboom.com/iboutlet-and-ibaction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Logging to Console</title>
		<link>http://clickflickboom.com/logging-to-console/</link>
		<comments>http://clickflickboom.com/logging-to-console/#comments</comments>
		<pubDate>Tue, 01 May 2012 22:30:18 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Diary Entry]]></category>
		<category><![CDATA[BOOL]]></category>
		<category><![CDATA[double]]></category>
		<category><![CDATA[int]]></category>
		<category><![CDATA[NSArray]]></category>
		<category><![CDATA[NSDate]]></category>
		<category><![CDATA[NSDictionary]]></category>
		<category><![CDATA[NSLog]]></category>
		<category><![CDATA[NSObject]]></category>
		<category><![CDATA[NSString]]></category>

		<guid isPermaLink="false">http://clickflickboom.com/?p=103</guid>
		<description><![CDATA[<p>Just a simple one for today, but an important one nonetheless: logging to console. Most of my experience logging to the console comes from JavaScript using console.log(). Objective-C&#8217;s equivalent is similar but – I feel like I&#8217;m saying this a lot lately – the syntax is a little strange to me. Anyway, logging to console [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p>Just a simple one for today, but an important one nonetheless: logging to console.</p>
<p>Most of my experience logging to the console comes from JavaScript using console.log(). Objective-C&#8217;s equivalent is similar but – I feel like I&#8217;m saying this a lot lately – the syntax is a little strange to me. Anyway, logging to console is done using NSLog, here are some examples:</p>
<h2>Simple</h2>
<p></p><pre class="crayon-plain-tag">NSLog(@&quot;Simple log&quot;);</pre><p></p>
<h2>Strings</h2>
<p></p><pre class="crayon-plain-tag">NSString *myString = @&quot;I am a string&quot;;
NSLog(@&quot;Value of myString is %@&quot;, myString);</pre><p></p>
<h2>Boolean</h2>
<p></p><pre class="crayon-plain-tag">BOOL myBool = YES;
NSLog(@&quot;Value of myBool is %d&quot;, myBool);
//or
NSLog(@&quot;Value of myBool is %@\n&quot;, (myBool ? @&quot;YES&quot; : @&quot;NO&quot;));</pre><p></p>
<h2>Dates</h2>
<p></p><pre class="crayon-plain-tag">NSDate *myDate = [NSDate date];
NSLog(@&quot;Value of myDate is %@&quot;, myDate);</pre><p></p>
<h2>Floats</h2>
<p></p><pre class="crayon-plain-tag">double myDouble = 1.5;
NSLog(@&quot;Value of myDouble is %f&quot;, myDouble);</pre><p></p>
<h2>Integer or Long</h2>
<p></p><pre class="crayon-plain-tag">int myInt = 90;
NSLog(@&quot;Value of myInt is %i&quot;, myInt);</pre><p></p>
<h2>Arrays &amp; Dictionaries</h2>
<p></p><pre class="crayon-plain-tag">NSArray * myArray = [NSArray arrayWithObjects:@&quot;Value 1&quot;, @&quot;Value 2&quot;, @&quot;Value 3&quot;, nil];
NSLog(@&quot;Value of myArray is %@&quot;, myArray);</pre><p></p>
<h2>NSObjects</h2>
<p>What if you want to print your ViewController, or some other object you&#8217;re working with, along with all its properties? You can do so using the same method as Arrays and Dictionaries, for example:</p><pre class="crayon-plain-tag">NSLog(@&quot;Dump of MyViewController %@&quot;, self);</pre><p>However, the output is going to be pretty underwhelming. Instead of a list of all properties, you&#8217;ll get something like this:</p>
<p><em>&lt;MyViewController: 0x6867e90&gt;</em></p>
<p>Not very useful :/</p>
<p>It turns out, all objects in Objective-C inherit from NSObject, and NSObject contains a method called description which you can exploit. Place this somewhere inside the implementation file:</p><pre class="crayon-plain-tag">- (NSString *)description {
    return [NSString stringWithFormat:@&quot;\nProperty 1: %@ \nProperty 2: %@&quot;, self.myProp, self.anotherProp];
}</pre><p>Doing this overrides the description method and allows you to control exactly what gets output to the console. Now whenever you NSLog your object, its description class will be run. Handy! :D</p>
]]></content:encoded>
			<wfw:commentRss>http://clickflickboom.com/logging-to-console/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Atomic vs Nonatomic</title>
		<link>http://clickflickboom.com/objective-c-atomic-vs-nonatomic/</link>
		<comments>http://clickflickboom.com/objective-c-atomic-vs-nonatomic/#comments</comments>
		<pubDate>Mon, 30 Apr 2012 22:30:54 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Diary Entry]]></category>
		<category><![CDATA[atomic]]></category>
		<category><![CDATA[nonatomic]]></category>
		<category><![CDATA[thread safety]]></category>

		<guid isPermaLink="false">http://clickflickboom.com/?p=128</guid>
		<description><![CDATA[<p>In an earlier post I discussed the difference between (strong) and (weak) attributes for a property. In this post I will discuss the difference between (atomic) and (nonatomic). Atomic Atomic is the default behaviour for a property; by not explicitly setting the above property as nonatomic, it will be atomic. An atomic property adds a [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p>In an earlier post I discussed <a title="Strong vs Weak" href="http://clickflickboom.com/strong-vs-weak/">the difference between (strong) and (weak)</a> attributes for a property. In this post I will discuss the difference between (atomic) and (nonatomic).</p>
<h2>Atomic</h2>
<p></p><pre class="crayon-plain-tag">@property (strong) NSMutableArray *myArray;</pre><p>Atomic is the default behaviour for a property; by not explicitly setting the above property as nonatomic, it will be atomic.</p>
<p>An atomic property adds a level of thread safety when getting or setting values. That is, the getter and setter for the property will always be fully completed regardless of what other threads are doing. The trade-off is that these properties will be a little slower to access than a nonatomic equivalent.</p>
<h2>Nonatomic</h2>
<p></p><pre class="crayon-plain-tag">@property (nonatomic, strong) NSMutableArray *myArray;</pre><p>Nonatomic properties are not thread safe, and will return their properties directly. This will be faster than atomic properties, but obviously carries some risk if precautions aren&#8217;t made.</p>
<h2>When is it Appropriate to Use Nonatomic?</h2>
<p>One thing I&#8217;ve noticed while following Objective-C tutorials and articles is that nonatomic is used most of the time. So if nonatomic is so risky, why is it used so often?</p>
<p>It&#8217;s all about performance. An atomic property&#8217;s getter and setter, conceptually, looks something like this:</p><pre class="crayon-plain-tag">-(NSString *) myString {
    @synchronized(self) {
        return myString;
    }
}

-(void) setMyString: (NSString *) newString {
    @synchronized(self)  {
         myString = newString;
    }
}</pre><p>Whereas a nonatomic property getter and setter looks something like this:</p><pre class="crayon-plain-tag">-(NSString *) myString {
    return myString;
}

-(void) setMyString: (NSString *) newString {
   myString = newString;
}</pre><p>It&#8217;s easy to see how the nonatomic implementation is going to be more light weight, but it does mean you have a responsibility to ensure problems don&#8217;t arise. Some articles I&#8217;ve read recommend keeping things atomic until performance becomes a problem, while others recommend the opposite.</p>
<p>In any event, if you decide to create a nonatomic property, here are some tips for keeping things thread safe:</p>
<ul>
<li>Use immutable objects where possible. For example, rather than creating an NSMutableArray, create an immutable NSArray. Whenever you need to add an object to it, create a mutable copy first and do what you need to do, then replace the entire property in one hit rather than tacking on another value to the end.</li>
<li>You can wrap potentially problematic sections of code with @synchronized.</li>
<li>UI code can always be nonatomic because UI code always happens on the main thread of the application.</li>
</ul>
<h2>Closing Comments</h2>
<p>It&#8217;s posts like this one that make me glad I&#8217;ve created this blog. Before today, I sort of knew the difference between the two in large strokes, but it wasn&#8217;t until I sat down and wrote this post that I was forced to ensure I really understood what I was tying. I had to research and understand thread safety before I could confidently hit the publish button.</p>
<p>To be honest, even now I&#8217;m terrified someone is going to chew me out in the comments. Be gentle ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://clickflickboom.com/objective-c-atomic-vs-nonatomic/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Strong vs Weak</title>
		<link>http://clickflickboom.com/strong-vs-weak/</link>
		<comments>http://clickflickboom.com/strong-vs-weak/#comments</comments>
		<pubDate>Sun, 29 Apr 2012 22:30:51 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Diary Entry]]></category>
		<category><![CDATA[ARC]]></category>
		<category><![CDATA[IBOutlet]]></category>
		<category><![CDATA[Properties]]></category>
		<category><![CDATA[strong]]></category>
		<category><![CDATA[weak]]></category>

		<guid isPermaLink="false">http://clickflickboom.com/?p=112</guid>
		<description><![CDATA[<p>One thing I&#8217;ve never had to worry about before with Web languages is memory management and reference counting. Thankfully iOS 5 has made the transition a little easier for me with Automatic Referencing Counting, which takes over a lot of the heavy lifting. Even so, there are still considerations that need to be made whenever [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p>One thing I&#8217;ve never had to worry about before with Web languages is memory management and reference counting. Thankfully iOS 5 has made the transition a little easier for me with Automatic Referencing Counting, which takes over a lot of the heavy lifting. Even so, there are still considerations that need to be made whenever a property is declared.</p>
<p>You have a choice between (strong) and (weak) when defining a property. In this post I&#8217;ll explain the difference between the two.</p>
<h2>Strong</h2>
<p></p><pre class="crayon-plain-tag">@property (strong) NSString *myString;</pre><p>This is the default state of a pointer, though I still like to explicitly state strong for clarity. A strong pointer will be retained as long as the class in which it was allocated remains.</p>
<h2>Weak</h2>
<p></p><pre class="crayon-plain-tag">@property (weak) NSString *myString;</pre><p>A weak reference means the pointer has no owner, therefore it will be deallocated as soon as it is no longer needed (that is, nothing else is pointing to it).</p>
<p>Most commonly, you would use weak for IBOutlets, such as UITextFIeld, UILabels and UIButton objects. Here&#8217;s an example:</p>
<p><a href="http://clickflickboom.com/strong-vs-weak/thebutton/" rel="attachment wp-att-118"><img class="aligncenter size-large wp-image-118" title="Weak Pointer Example" src="http://clickflickboom.com/wp-content/uploads/2012/04/thebutton-500x80.png" alt="" width="500" height="80" /></a></p>
<p>In this case, I&#8217;m creating an IBOutlet for a button (theButton) in my view within my controller. The theButton object belongs to my view, not my controller, so in this case a weak attribute makes more sense than strong. In fact, as a general rule IBOutlets should always be set to weak.</p>
]]></content:encoded>
			<wfw:commentRss>http://clickflickboom.com/strong-vs-weak/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
