<?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>Rapture In Venice: iOS, Android Mobile Development Shop</title>
	<atom:link href="http://raptureinvenice.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://raptureinvenice.com</link>
	<description>:: Mobile Design and Development Shop specializing in iPhone, iPad, and Android</description>
	<lastBuildDate>Mon, 02 Apr 2012 05:21:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>InnerBand Tutorial Part 3: The Magical Message Center</title>
		<link>http://raptureinvenice.com/innerband-3/</link>
		<comments>http://raptureinvenice.com/innerband-3/#comments</comments>
		<pubDate>Mon, 02 Apr 2012 04:33:12 +0000</pubDate>
		<dc:creator>John Blanco</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[InnerBand]]></category>
		<category><![CDATA[Message Center]]></category>
		<category><![CDATA[RaptureXML]]></category>
		<category><![CDATA[Sample Project]]></category>

		<guid isPermaLink="false">http://raptureinvenice.com/?p=726</guid>
		<description><![CDATA[This is the third part of a multi-part series on the InnerBand Framework. Previously, in InnerBand Tutorial Part 2: Core Data Quick and Easy!, I reviewed the Core Data Store and how it makes working with Core Data actually&#8230;kinda fun! From the community of InnerBand developers, I&#8217;ve heard nothing but compliments and happiness about what [...]]]></description>
			<content:encoded><![CDATA[<p><i>This is the third part of a multi-part series on the <a href="https://github.com/ZaBlanc/InnerBand">InnerBand Framework</a>.  Previously, in <a href="http://raptureinvenice.com/innerband-2/">InnerBand Tutorial Part 2: Core Data Quick and Easy!</a>, I reviewed the Core Data Store and how it makes working with Core Data actually&#8230;kinda fun!</i></p>
<p>From the community of InnerBand developers, I&#8217;ve heard nothing but compliments and happiness about what it does for them. They love the macros and functions that keep their code concise, the category methods that are so useful they can&#8217;t imagine living without them, the Core Data Store which brings them sanity, and then classes like <i>IBAlertView</i> which demonstrate why blocks are so darn awesome.  I <b>love</b> that <i>they</i> love InnerBand, but there&#8217;s one piece of it that they never seem to mention: <i>Message Center</i>.</p>
<p>I can&#8217;t blame them.  For one thing, it&#8217;s never been documented.  Second, if any enterprising developer did read analyze the code, they would likely be left with no motivation to use it.  Is that assessment fair?  <b>NO</b>.</p>
<p>So, what does it do then?</p>
<h3>What Is the Message Center?</h3>
<p>On the face of it, the Message Center is very similar to the <i>NSNotificationCenter</i> provided by Apple.  It allows objects to listen for notifications (dispatch messages) from other objects, send them, include message-specific information by way of an NSDictionary, and stop listening as well. The familiarity is intentional so that other iOS developers would pick up on it quickly.</p>
<p>Let&#8217;s see how the basics work.  As an example, let&#8217;s presume we have two objects, myWeatherWidget and myWeatherReporter. When myWeatherReporter updates the weather forecast, it notifies its listeners. When myWetherWidget gets the notification, it updates its UI to reflect the new information.  Got it?</p>
<p>Here&#8217;s the most basic way myWeatherReporter can notify its listeners:</p>
<pre class="brush: objc; title: ; notranslate">
[MessageCenter sendGlobalMessageNamed:MSG_FORECAST_UPDATED];
</pre>
<p>The MessageCenter is used in static form; no need to access a singleton or <i>defaultCenter</i>.  This particular code dispatches a global message so that you only need to provide the name, but you can provide the source object so listeners can be more discriminating.  Everything else is done for you.  If you were using the <i>NSNotificationCenter</i>, you&#8217;d of had to specify the source object as <i>nil</i> to get the &#8220;global&#8221; behavior.  Note, also, that MSG_FORECAST_UPDATE is any arbitrary, unique string (Personally, I tender to define it as the same name as the constant).</p>
<p>If we want to pass along the weather information along with the message, we&#8217;d do it like this:</p>
<pre class="brush: objc; title: ; notranslate">
[MessageCenter sendGlobalMessageNamed:MSG_FORECAST_UPDATED withObjectsAndKeys:weatherInfo, @&quot;info&quot;, nil];
</pre>
<p>There are actually several versions of the above you could use depending on your style preference, such as with <i>sendGlobalMessageNamed:withUserInfoKey:andValue:</i>, but they all do the same thing which is to package data in the message&#8217;s <i>userInfo</i> property.</p>
<p>For an object to receive the message, it must register itself as a listener and provide a method:</p>
<pre class="brush: objc; title: ; notranslate">
- (void)viewDidLoad {
    [super viewDidLoad];
    [MessageCenter addGlobalMessageListener:MSG_FORECAST_UPDATED target:self action:SEL(forecastUpdated:)];
}

- (void)forecastUpdated:(DispatchMessage *)msg {
    NSDictionary *userInfo = msg.userInfo;
    ...
}
</pre>
<p>Self-explanatory.  Again, you don&#8217;t have to make these global messages if you want to be more specific. Also, you don&#8217;t have to accept the <i>DispatchMessage</i> argument if you don&#8217;t need it.  Remember, too, that your objects should remove themselves as a listener before being deallocated.  I tend to make the object add itself as a listener in <i>viewDidLoad</i> and unregister accordingly:</p>
<pre class="brush: objc; title: ; notranslate">
- (void)viewDidLoad {
    [super viewDidLoad];
    [MessageCenter addGlobalMessageListener:MSG_FORECAST_UPDATED target:self action:SEL(forecastUpdated:)];
}

- (void)viewDidUnload {
    [MessageCenter removeMessageListenersForTarget:self];
    [super viewDidUnload];
}

- (void)dealloc {
    [MessageCenter removeMessageListenersForTarget:self];
}
</pre>
<p>In 99% of cases, when you unregister a listener you mean to unregister for <i>everything</i> the object is listening to (i.e., the object is going away).  If you want to stop listening to just one type of message, there are plenty of methods for handling that case such as <i>removeMessageListener:target:action:</i>.</p>
<p>This is the basic Observer pattern as Message Center implements it.  Minus a little more conciseness, you already have that with <i>NSNotificationCenter</i>.  Now, let&#8217;s see why you&#8217;ll never want to use <i>NSNotificationCenter</i> ever again!</p>
<h3>What Makes Message Center Awesome?!</h3>
<p>What makes Message Center superior to <i>NSNotificationCenter</i> is that it helps you get your real-world work done much faster. For this example, I&#8217;ll be referencing the <i>Movie Poster Fetcher</i> which you can <a href="http://raptureinvenice.com/blog-files/MoviePosterFetcher.zip">download</a> and use as inspiration.  What this little app does is let you enter in the name of your favorite movie and it will display the movie poster and some other information.  Seems simple enough, but keep in mind that an app like this has a few components you&#8217;d normally have to deal with:</p>
<ul>
<li>You need to construct the GET request to get the movie poster information.
<li>You need to create handlers for receiving the response as well as the streaming data.
<li>You need to spin a thread that will process the response.
<li>You need to handle errors.
<li>You need to notify listeners that you have the new data ready.
<li>You need to display that information.
</ul>
<p>Everyone, and I mean <b>everyone</b>, writes this code differently.  If you like to use <i>NSNotificationCenter</i>, you might notify once when the data comes in and then that listener will notify a second time when it&#8217;s done processing it.  You might use an asynchronous NSURLRequest, NSOperationQueue, dispatch queues, <a href="http://allseeing-i.com/ASIHTTPRequest/">ASIHTTP</a>, <a href="https://github.com/samvermette/SVHTTPRequest">SVHTTPRequest</a>, or any number of other methods.  It really makes for a great interview challenge, eh?</p>
<p>Here&#8217;s how you would do it with the Message Center:</p>
<pre class="brush: objc; title: ; notranslate">
- (void)requestMoviePosterForTitle:(NSString *)title {
    NSString *url = @&quot;http://www.imdbapi.com/?i=&amp;t=[TITLE]&amp;r=XML&quot;;
    NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:title, @&quot;TITLE&quot;, nil];

    __block HTTPGetRequestMessage *get = [HTTPGetRequestMessage messageWithName:MSG_POSTER_RECEIVED userInfo:userInfo url:url processBlock:^(NSData *stream, NSInteger httpResponse) {
        if (httpResponse == 200) {
            RXMLElement *rxml = [RXMLElement elementFromXMLData:stream];

            // process xml and supply it to the listeners
            if ([rxml isValid]) {
                RXMLElement *movieElement = [rxml child:@&quot;movie&quot;];

                [get setUserInfoValue:[movieElement attribute:@&quot;title&quot;] forKey:@&quot;title&quot;];
                [get setUserInfoValue:[movieElement attribute:@&quot;poster&quot;] forKey:@&quot;poster&quot;];
            }
        }
    }];

    // dispatch
    [MessageCenter sendGlobalMessage:get];
}
</pre>
<p>Wait, wait&#8230;WHOA, WHOA.  Stop right there! I&#8217;ve seen that look before.  This is the part of the tutorial where you&#8217;re disappointed to see all this unfamiliar, fairly bulky code and you just lose confidence that this is the framework you&#8217;ve been looking for all your life.  Well, <b>no</b>, <b>no</b>, <b>no</b>, you keep reading!  Look at the code again!  This code does <b>everything</b>.  It&#8217;s performing the HTTP GET request, it&#8217;s checking the response, it&#8217;s even processing the XML! (Thanks to <a href="https://github.com/ZaBlanc/RaptureXML">RaptureXML</a>!)  </p>
<p>Let&#8217;s review it line by line:</p>
<ul>
<li><b>Lines 2 &#8211; 3</b> &#8211; We define the URL with parameters that will be substituted automatically.  In this case, [TITLE] will be replaced by the title string we provide.  In the real world, the URL would be a constant, and this is a cleaner syntax to read than a string formatter. (But you&#8217;re free to do it yourself if you like. No biggie.)
<li><b>Line 5</b> &#8211; We define the HTTP GET request.  This is the magic!  The request is a message itself and it&#8217;ll process the request <i>before</i> dispatching to the listeners.  Essentially, you&#8217;re telling this thing to do the request, and when it&#8217;s all done let the listeners know.  This is remarkably different from what you usually see which is a message simply having a name and no other utility.
<li><b>Line 6</b> &#8211; This is the processing block.  More magic!  The idea here is that we&#8217;ll process the response immediately when it comes, and only when that&#8217;s been done do we notify the listeners.  The reason we do it this way is because if we waited for a listener to process the XML, then we could only let one listener handle it.  That, or every listener would have to process the XML itself because the order can&#8217;t be guaranteed!
<li><b>Lines 7 &#8211; 12</b> &#8211; This is RaptureXML doing its thing.  It tears apart the XML in a laughably tiny amount of code.
<li><b>Lines 13 &#8211; 14</b> &#8211; Here&#8217;s where we take the two bits of information we care about (movie title and poster URL) and add them to the user info of the message.  Every listener will now get this information!  Note that while you can add information anytime you like, you shouldn&#8217;t really do it in the listeners themselves because the order can&#8217;t be guaranteed. However, in a processing block, it&#8217;s perfect! (Obviously, you can store the information in Core Data, too.)
<li><b>Line 20</b> &#8211; This is where we dispatch the message.  All the magic happens only after we dispatch.  Remember, the processing block is called before the listeners get notified!
</ul>
<p>Look at this code and really think about it.  There&#8217;s no wasted space.  Everything does it&#8217;s job succinctly, efficiently, and clearly.  And in this tiny amount of space, we&#8217;ve written all the web service integration code we need.</p>
<p>With Message Center, we can do HTTP POST as well.  We can also define our own message subclasses, too, that we can re-use over and over again!  Dump your <a href="https://github.com/johnezang/JSONKit">JSONKit</a> processing code in a message and have it automatically decoded for you en route to your listeners.  Wrap sound effects in messages.  Anywhere you take input and produce output you can create a message that will do it for you while you dispatch!</p>
<h3>What Else Does Message Center Do?</h3>
<p>If that&#8217;s all you got from Message Center, trust me, you&#8217;re gonna live a happy life.  But there&#8217;s more, but I&#8217;ll offer it with one caveat: you might not ever need it.  The reason is that most of this stuff preceded the process block style you see above. (InnerBand itself preceded blocks.)  For example, a <i>SequencedMessage</i> lets you chain together a set of messages in such a way that the output of each message is fed into the input of the following message like a human centipede.  How is this valuable?  Think if you had a message that handled HTTP GET requests and a message that processed JSON.  You could chain these together into one <i>SequencedMessage</i>, dispatch, have the HTTP GET request your data, have the JSON message process your data, and only then would all the listeners receive it without any of them having to handle the processing!</p>
<p>Cool, right?  But since that&#8217;s the prototypical use case, processing blocks blow it away because there&#8217;s no need to subclass and all the code stays in one place.  Still, the SequencedMessage lets you take advantage of DispatchMessage subclasses that you create and chain them together like high-tech legos.  It&#8217;s good to be aware of.</p>
<p>While subclassing is great for chaining, also keep in mind that BlockBasedDispatchMessage alleviates even that.  By providing your input and output handlers as blocks, you avoid the hassle and bulk of new classes.  Be sure to check those out as well!</p>
<h3>Summary</h3>
<p>The Message Center is a similar, but more powerful, version of the <i>NSNotificationCenter</i> that fundamentally redefines the role of the message.  Instead of just being a named thing, it&#8217;s a named thing that performs functionality before it dispatches to its listeners, either synchronously or asynchronously.  Processing blocks serve as guaranteed, called-first code that empowers you to have multiple listeners without having to split the flow into two parts, one listener processing the response and the other listeners to update based on that new data.</p>
<p>In its most basic form, Message Center lets you loosely couple message sending between components of your application.  In its most useful form, Message Center lets you send HTTP requests, process the responses, and then notify listeners of the data in one short, sweet step!</p>
<p>Again, take a look at the <a href="http://raptureinvenice.com/blog-files/MoviePosterFetcher.zip">Movie Poster Fetcher</a> and see the magic for yourself!</p>
]]></content:encoded>
			<wfw:commentRss>http://raptureinvenice.com/innerband-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I Have An Idea for an App!  Now What?!</title>
		<link>http://raptureinvenice.com/i-have-an-idea-for-an-app-now-what/</link>
		<comments>http://raptureinvenice.com/i-have-an-idea-for-an-app-now-what/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 05:06:41 +0000</pubDate>
		<dc:creator>John Blanco</dc:creator>
				<category><![CDATA[Consulting]]></category>

		<guid isPermaLink="false">http://raptureinvenice.com/?p=694</guid>
		<description><![CDATA[It&#8217;s 10:00 AM, you&#8217;re in your office (or better yet, on your couch) dreaming up million-dollar app ideas when &#8212; BAM! &#8212; like a bolt of lightning it hits you. EUREKA! You have conceived of The Next Big Thing&#0153;: an app that will change the world, or at the very least provide your company a [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s 10:00 AM, you&#8217;re in your office (or better yet, on your couch) dreaming up million-dollar app ideas when &#8212; <i><b>BAM!</b></i> &#8212; like a bolt of lightning it hits you.  EUREKA!  You have conceived of The Next Big Thing&#0153;: an app that will change the world, or at the very least provide your company a hefty income boost (and for you a big, fat bonus).  You call up your boss and tell her your brilliant idea and she concurs, &#8220;Make it happen, fast!&#8221;</p>
<p>And now.  All you need to do.  Is find someone who can build. Your app&#8230;&#8230;&#8230;&#8230;..huh.</p>
<p>Well, how the heck do you go about doing that?  The Internet is a horrifying place after all.  You start with a quick google &#8220;i want to create an app&#8221; and find <a href="http://mashable.com/2011/12/28/app-cooker-design/">App Cooker</a>.  Hey, an app to make an app!  This&#8217;ll be easy, maybe you can do it yourself, too! You read through it a little bit and then, meh, your excitement dwindles.  It&#8217;s just another development environment.  You&#8217;ll still need to hire someone to do it for you.</p>
<p><i>(It&#8217;s also worth noting that you not only still have to write the app, but you&#8217;ll be doing it with App Cooker instead of the Apple SDK, thereby giving you only a small fraction of the talent pool to draw upon when hiring.)</i></p>
<p>Stiff upper lip!  Undeterred, you google &#8220;iphone app developer&#8221;.  Better!  Hmmm, Apple link, Apple link&#8230;ah! Here&#8217;s <a href="http://www.iphoneappquotes.com/">iPhoneAppQuotes.com</a>.  Let&#8217;s see, you give your contact info and<i>&#8230;yadda yadda yadda&#8230;</i>a company will contact you. What company?  Where are they located?  Where can you find some all-important examples of their work?  I mean, are you willing to spend an hour or more of your precious time talking to some company you&#8217;d never want to work with anyway?</p>
<p>Take a closer look at the site.  The top quote from the site (as I read it right now) is for <i>Count Trackula</i>.  Sounds like the developer they were paired up with did a good job.  Let&#8217;s take a look at the app:</p>
<p><a href="http://raptureinvenice.com/wp-content/uploads/2012/02/mzl.quhrayvy.320x480-75.jpg"><img src="http://raptureinvenice.com/wp-content/uploads/2012/02/mzl.quhrayvy.320x480-75-200x300.jpg" alt="" title="Count Tracula, a generic counting app now available in the App Store and made by iPhoneAppQuotes.com" width="200" height="300" class="aligncenter size-medium wp-image-696" /></a></p>
<p>Wait, it&#8217;s spelled <i>Count Tracula</i>?  They didn&#8217;t even spell it right?  And whoa! Look at that app, it&#8217;s horrible looking!  Apparently some iPhone novice signed up to get quotes and won the bid!  Do you want to be showing an app like that to <b>your</b> boss?</p>
<p>That product isn&#8217;t going to change the world. It may not even get downloaded much at all.</p>
<p>Alright, alright, don&#8217;t be depressed.  Cheer up!  You won&#8217;t get an app that looks like that unless you make a seriously bad choice in who you entrust your app to.  But what choice <i>should</i> you make?  Well, you can&#8217;t decide on who should create your app until you have an idea of the types of options you have.</p>
<p>So, let&#8217;s talk about the three kinds of app makers you&#8217;ll find out there: The Big Firm, The Lone Consultant, and the Streamlined Mobile Shop.</p>
<h3>The Big Firm</h3>
<p>The Big Firm is a very common first destination for most people who&#8217;re looking to build an app.  Why?  Because these companies have huge budgets for marketing and PR and you&#8217;ll find a <a href="http://mcfaddenplace.com/2011/11/effectiveui-and-15-million-elephants-help-%E2%80%98fight-the-famine%E2%80%99/">seemingly</a> <a href="http://www.prnewswire.com/news-releases/double-encore-completes-acquisition-of-iphone-application-studio-90732579.html">endless</a> <a href="http://www.businesswire.com/news/home/20100105006736/en/Roundarch-Releases-Top-Digital-Marketing-Strategies-2010">supply</a> <a href="http://www.24-7pressrelease.com/press-release-rss/law-of-attraction-unites-with-pma-in-universal-mind-hive-manifestmyworldcom-launches-global-community-to-manifest-dreams-240538.php">of</a> <a href="http://www.pr-inside.com/effectiveui-harnesses-the-power-of-r1151605.htm">uninteresting</a> <a href="http://www.effectiveui.com/news-events/11-10-2010.php">press releases</a> flooding the search engines.</p>
<p>You can&#8217;t help but find them, but does that make them the best choice?</p>
<p>These big firms mask a dirty little secret.  Behind their polished façade, you&#8217;ll often find a technical company with a high turnover rate, low-balled proposals that stress their development teams, and a large number of sub-contractors who are the ones working on your app.  In other words, they&#8217;re publicized middle men.</p>
<p>As a member of one of these Big Firms, I once saw an entire 8-man team filled almost entirely by consultants hired in a matter of 2 days.  None of them knew each other or were associated with the Big Firm in any way.  In other words, the client could have had the same development team at half the cost if they&#8217;d just interviewed and found the team itself!</p>
<p>This probably isn&#8217;t what you want.  These Big Firms work out better for much larger clients who aren&#8217;t always looking for the best team for the job but rather tangible accountability.  Someone that they can <a href="http://dockets.justia.com/docket/colorado/codce/1:2011cv01259/126031/">sue</a> if things don&#8217;t go exactly how they want.  If your company restricts the use of open source applications because it requires support agreements with its software vendors, then this is the choice for you.</p>
<p>Cost can also be quite prohibitive.  Hourly rates for the Big Firms range from $125 to $175.  And you&#8217;re paying for everybody who works on the app: developers, designers, project managers, testers, and sub-contractors. Just one meeting alone with them can reasonably cost you $5,000.  Wow.</p>
<p>It&#8217;s not all bad, though.  The Big Firms often carry some sway in the industry.  It can be beneficial to have your app linked to one of these companies.  They&#8217;ll help promote your app, too, and since they have so many resources at their disposal you&#8217;ll never be abandoned. There&#8217;ll always be someone available to work on your app.</p>
<p>It&#8217;s a big cost for a big team and a quality result, but if a six-figure iPhone app isn&#8217;t your cup of tea, is there a cheaper option to go with? </p>
<h3>The Lone Consultant</h3>
<p>Affordable, available, and offering the most direct communication possible, the Lone Consultant is the best choice for the truly small budget.</p>
<p>Here&#8217;s the truth about the Lone Consultant that the Big Firms don&#8217;t want you to know: the Lone Consultant used to work for the Big Firms.  Me included.  In general, your typical Big Firm will pay an employee approximately 25-35% of the hourly rate they are billing to you, the client. And so one day that employee, realizing that they&#8217;re the ones who are creating the apps for the Big Firms&#8217; clients, decides to go independent and leave.</p>
<p>Yes, they&#8217;ll have to go out and find their own clients now, but they&#8217;ll be paid more handsomely for the same work they were doing before.  Remember when I said middle man? The Lone Consultant will charge an hourly rate between $50 and $100. Why can they charge a lot less?  Because you&#8217;re paying them directly.  They&#8217;re making more; you&#8217;re paying less. Everyone wins!</p>
<p>Additionally, you can talk to the Lone Consultant directly. This saves you time not having to negotiate project details through a Project Manager, whom you&#8217;ll be talking to with the Big Firm. </p>
<p>The Lone Consultant is a fine choice, but there are some pitfalls to be mindful of.  First, they&#8217;re going to be a developer, so you need to make sure you have an understanding of where the design talent will come from &#8212; if any.  You might be responsible for finding that talent on your own, too, which leads to the biggest problem: you get to play Project Manager!</p>
<p>In some cases, this may be what you want, but most likely you&#8217;re looking for someone to create your app because you have no idea how to do it yourself.  Managing a technical project isn&#8217;t easy, especially if you have hard deadlines.  What will you do if the developer quits the contract?  Can you find someone willing to take over an abandoned codebase?  Is the designer overcharging on their hours?  How would you even tell if they were?</p>
<p>If you&#8217;re willing to take on the responsibility, the Lone Consultant is the most cost-effective option.  But, if the Big Firm is too bloated and the Lone Consultant requires too much micro-management on your part, what is the reasonable alternative?</p>
<h3>The Streamlined Mobile Shop</h3>
<p>The Streamlined Mobile Shop combines the team effort of the Big Firm with the more efficient communication of the Lone Consultant.  Hourly rates range between $75 and $125 and fixed bids are common as well.  The Streamlined Mobile Shop is employed by a handful of people, likely all designers and developers, so there&#8217;s no expensive overhead you&#8217;ll have to pay for. They&#8217;ll manage your project for you and give you better quality work per dollar than the Big Firm can.</p>
<p>My favorite aspect of the Streamlined Mobile Shop is that it&#8217;s made up of some of the most dedicated people.  These groups are already stocked with great talent, but since the group is kept small, there&#8217;s great camaraderie.  And the good mood will make for a better working relationship for you, too.</p>
<h3>Let&#8217;s Break It Down, Then</h3>
<p>Now that you have a good idea of who to choose, who&#8217;s it gonna be?  My recommendation, if your budget allows, is to go with the Streamlined Mobile Shop because you&#8217;ll get the best service at the most reasonable cost. It&#8217;s why I&#8217;m a part of one. Yet, if you&#8217;re organization is too big or too small, it may not be possible to in this direction.</p>
<p>So, there you go.  You still need to make a choice!  What will it be? Let&#8217;s summarize everything we&#8217;ve talked about now.</p>
<table>
<tr>
<th>&nbsp;</th>
<th>The Lone Consultant</th>
<th>The Streamlined Mobile Shop</th>
<th>The Big Firm</th>
</tr>
<tr>
<th># of Employees</th>
<td align="center">1</td>
<td align="center">2-25</td>
<td align="center">26-200+</td>
</tr>
<tr>
<th># of Concurrent Projects</th>
<td align="center">1-2</td>
<td align="center">2-3</td>
<td align="center">4-8+</td>
</tr>
<tr>
<th>Who You&#8217;ll Talk To</th>
<td align="center">Developer</td>
<td align="center">CTO or Lead Developer</td>
<td align="center">Project Manager</td>
</tr>
<tr>
<th>Hourly Rate<br />(per person)</th>
<td align="center">$70 &#8211; $125</td>
<td align="center">$85 &#8211; $150</td>
<td align="center">$125 &#8211; $175</td>
</tr>
<tr>
<th>Minimum Budget to Do Business</th>
<td align="center">$1,000</td>
<td align="center">$5,000</td>
<td align="center">$25,000</td>
</tr>
</tr>
</table>
<p>So there we go. Well, good luck with that app.  I hope to see it in the App Store soon! <img src='http://raptureinvenice.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://raptureinvenice.com/i-have-an-idea-for-an-app-now-what/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What Can RIV Do For You?</title>
		<link>http://raptureinvenice.com/carousel-2/</link>
		<comments>http://raptureinvenice.com/carousel-2/#comments</comments>
		<pubDate>Sun, 12 Feb 2012 02:46:50 +0000</pubDate>
		<dc:creator>John Blanco</dc:creator>
				<category><![CDATA[Promotion]]></category>

		<guid isPermaLink="false">http://raptureinvenice.com/?p=654</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<div id="portfolio-slideshow0" class="portfolio-slideshow">
	<div class="slideshow-next slideshow-content">
			<a href="javascript: void(0);" class="slideshow-next"><img class="psp-active" data-img="http://raptureinvenice.com/wp-content/uploads/2012/02/aa-carousel4.png" src="http://raptureinvenice.com/wp-content/uploads/2012/02/aa-carousel4.png" height="505" width="645" alt="aa-carousel" /><noscript><img src="http://raptureinvenice.com/wp-content/uploads/2012/02/aa-carousel4.png" height="505" width="645" alt="aa-carousel" /></noscript></a></div>
			<div class="not-first slideshow-next slideshow-content">
			<a href="javascript: void(0);" class="slideshow-next"><img class="psp-active" data-img="http://raptureinvenice.com/wp-content/uploads/2012/02/passtouch-carousel4.png" src="http://raptureinvenice.com/wp-content/plugins/portfolio-slideshow/img/tiny.png" height="505" width="645" alt="passtouch-carousel" /><noscript><img src="http://raptureinvenice.com/wp-content/uploads/2012/02/passtouch-carousel4.png" height="505" width="645" alt="passtouch-carousel" /></noscript></a></div>
			<div class="not-first slideshow-next slideshow-content">
			<a href="javascript: void(0);" class="slideshow-next"><img class="psp-active" data-img="http://raptureinvenice.com/wp-content/uploads/2012/02/tasklist-carousel4.png" src="http://raptureinvenice.com/wp-content/plugins/portfolio-slideshow/img/tiny.png" height="505" width="645" alt="tasklist-carousel" /><noscript><img src="http://raptureinvenice.com/wp-content/uploads/2012/02/tasklist-carousel4.png" height="505" width="645" alt="tasklist-carousel" /></noscript></a></div>
			<div class="not-first slideshow-next slideshow-content">
			<a href="javascript: void(0);" class="slideshow-next"><img class="psp-active" data-img="http://raptureinvenice.com/wp-content/uploads/2012/02/ss-carousel4.png" src="http://raptureinvenice.com/wp-content/plugins/portfolio-slideshow/img/tiny.png" height="505" width="645" alt="ss-carousel" /><noscript><img src="http://raptureinvenice.com/wp-content/uploads/2012/02/ss-carousel4.png" height="505" width="645" alt="ss-carousel" /></noscript></a></div>
			<div class="not-first slideshow-next slideshow-content">
			<a href="javascript: void(0);" class="slideshow-next"><img class="psp-active" data-img="http://raptureinvenice.com/wp-content/uploads/2012/02/fuzz-carousel4.png" src="http://raptureinvenice.com/wp-content/plugins/portfolio-slideshow/img/tiny.png" height="505" width="645" alt="fuzz-carousel" /><noscript><img src="http://raptureinvenice.com/wp-content/uploads/2012/02/fuzz-carousel4.png" height="505" width="645" alt="fuzz-carousel" /></noscript></a></div>
			<div class="not-first slideshow-next slideshow-content">
			<a href="javascript: void(0);" class="slideshow-next"><img class="psp-active" data-img="http://raptureinvenice.com/wp-content/uploads/2012/02/wwp-carousel3.png" src="http://raptureinvenice.com/wp-content/plugins/portfolio-slideshow/img/tiny.png" height="505" width="645" alt="wwp-carousel" /><noscript><img src="http://raptureinvenice.com/wp-content/uploads/2012/02/wwp-carousel3.png" height="505" width="645" alt="wwp-carousel" /></noscript></a></div>
			<div class="not-first slideshow-next slideshow-content">
			<a href="javascript: void(0);" class="slideshow-next"><img class="psp-active" data-img="http://raptureinvenice.com/wp-content/uploads/2012/02/is-carousel4.png" src="http://raptureinvenice.com/wp-content/plugins/portfolio-slideshow/img/tiny.png" height="505" width="645" alt="is-carousel" /><noscript><img src="http://raptureinvenice.com/wp-content/uploads/2012/02/is-carousel4.png" height="505" width="645" alt="is-carousel" /></noscript></a></div>
			<div class="not-first slideshow-next slideshow-content">
			<a href="javascript: void(0);" class="slideshow-next"><img class="psp-active" data-img="http://raptureinvenice.com/wp-content/uploads/2012/02/hoya-carousel4.png" src="http://raptureinvenice.com/wp-content/plugins/portfolio-slideshow/img/tiny.png" height="505" width="645" alt="hoya-carousel" /><noscript><img src="http://raptureinvenice.com/wp-content/uploads/2012/02/hoya-carousel4.png" height="505" width="645" alt="hoya-carousel" /></noscript></a></div>
			</div><!--#portfolio-slideshow--></div><!--#slideshow-wrapper-->
]]></content:encoded>
			<wfw:commentRss>http://raptureinvenice.com/carousel-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ARC Support Without Branching</title>
		<link>http://raptureinvenice.com/arc-support-without-branches/</link>
		<comments>http://raptureinvenice.com/arc-support-without-branches/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 18:08:44 +0000</pubDate>
		<dc:creator>John Blanco</dc:creator>
				<category><![CDATA[Consulting]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[ARC]]></category>
		<category><![CDATA[InnerBand]]></category>
		<category><![CDATA[macros]]></category>

		<guid isPermaLink="false">http://raptureinvenice.com/?p=505</guid>
		<description><![CDATA[When Apple announced support for ARC (Automatic Reference Counting), iOS developers jumped for joy at the prospect of no longer having to litter codebases with manual memory management code anymore. Finally, we can concentrate on logic without all the error-prone, time-consuming boilerplate. But, even moreso than most of the new features in iOS5, the transition [...]]]></description>
			<content:encoded><![CDATA[<p>When Apple announced support for ARC (Automatic Reference Counting), iOS developers jumped for joy at the prospect of no longer having to litter codebases with manual memory management code anymore.  Finally, we can concentrate on logic without all the error-prone, time-consuming boilerplate.  But, even moreso than most of the new features in iOS5, the transition period for ARC has been a bit painful.</p>
<h3>The Problem</h3>
<p>The decision to support ARC in your project is clear cut.  Yes or no.  Most iOS developers use ARC for all new projects that only require a minimum of 4.0 support.  (ARC is not supported by iOS 3.1.3.) However, if you are the author of a framework or library, the decision to support ARC isn&#8217;t so easy and there are several choices you can make.</p>
<p>The easiest way to go about it is not to convert to ARC at all.  Developers can still use your library source code by specifying the <i>-fno-objc-arc</i> option in their project&#8217;s <i>Project Sources</i> section.</p>
<div id="attachment_507" class="wp-caption alignleft" style="width: 310px"><a href="http://raptureinvenice.com/wp-content/uploads/2012/01/Screen-Shot-2012-01-29-at-10.08.47-AM.png"><img src="http://raptureinvenice.com/wp-content/uploads/2012/01/Screen-Shot-2012-01-29-at-10.08.47-AM-300x23.png" alt="An example of the -fno-objc-arc option" title="An example of the -fno-objc-arc option" width="300" height="23" class="size-medium wp-image-507" /></a><p class="wp-caption-text">An example of the -fno-objc-arc option</p></div>
<p>A big problem with this approach is requiring that option at all.  It has to be specified on a per-file basis and, if your library consists of many files such as <a href="">Cocos2D</a>, the developer would have to set the option for all of them.  The XCode interface for this is pretty convoluted and many developers are unaware of the option or where to specify it.  Also, if they later updates the library in their project, XCode removes the option and it has to be entered all over again.  Pretty obnoxious, and a poor reflection on your code.</p>
<p>Another way to go is to just convert your library to ARC-only. Anyone who isn&#8217;t using ARC for their project will have memory leaks and likely a ton of warnings from their static analyzer.  This isn&#8217;t a realistic option right now.  Once a much larger percentage of iOS developers are using ARC it will be.  There&#8217;s just too many non-ARC projects still out there, especially if iOS 3.1.3 support is required.</p>
<p>So, many developers have decided to add ARC support.  A common way is to add a branch to their project that supports ARC.  <a href="https://github.com/TouchCode/TouchXML">TouchXML</a>, <a href="https://github.com/TouchCode/TouchJSON">TouchJSON</a>, <a href="https://github.com/nfarina/xmldocument">XMLDocument</a>, and <a href="https://github.com/jverkoey/nimbus">Nimbus</a> are just a small handful of projects that have taken this approach. <a href="https://github.com/samvermette/SVProgressHUD#readme">SVProgressHUD</a> even tried such a branch and abandoned it completely due to the complexity and undesirability of doing such a silly thing! </p>
<p>I highly dissuade you from this approach.  Maintaining two branches is rarely a good idea in the real world, let alone for a simple, open-source iOS library.  It adds a little complexity to grabbing your source code and will inevitably lead to some commit issues.</p>
<p>There&#8217;s a better way.</p>
<h3>The Basic Solution</h3>
<p>The solution to the problem is conditional compilation.  Yes, it&#8217;s not only possible, but rather straightforward, to write your code so that it automatically detect the context it&#8217;s running in.  You won&#8217;t have to maintain a second branch and you&#8217;ll be able to support ARC and non-ARC code right out of the box.</p>
<p>There&#8217;s two methods for doing this and both use the same basic check:</p>
<pre class="brush: objc; title: ; notranslate">
#if __has_feature(objc_arc)
    ...ARC code here...
#else
    ...non-ARC code here...
#endif
</pre>
<p>The <i>__has_feature(objc_arc)</i> check will not compile the enclosed code for any compiler that doesn&#8217;t support ARC, nor for the LLVM 3.0 compiler if ARC isn&#8217;t enabled. You can certainly use this code structure and separate your ARC and non-ARC code without reading any further, but if you do you might quickly discover your code will become a mess very quickly. In addition, XCode has historically done a pretty shitty job of automatically indenting code when you use conditional compilation.</p>
<p>How do we keep the code clean?</p>
<h3>The Macro Solution</h3>
<p>If you want your code to retain (no pun intended) a level of simple readability, macros are definitely the way to go.  The idea is that instead of writing completely separate lines of code for ARC and non-ARC, you write macros that adapt to the environment instead.</p>
<p>This is best described by presenting the set of macros which you&#8217;re free to drop in to your own project (<a href="http://raptureinvenice.com/blog-files/ARCMacros.h">ARCMacros.h</a>):</p>
<pre class="brush: objc; title: ; notranslate">
//
//  ARCMacros.h
//
//  Created by John Blanco on 1/28/2011.
//  Rapture In Venice releases all rights to this code.  Feel free use and/or copy it openly and freely!
//

#if !defined(__clang__) || __clang_major__ &lt; 3
    #ifndef __bridge
        #define __bridge
    #endif

    #ifndef __bridge_retain
        #define __bridge_retain
    #endif

    #ifndef __bridge_retained
        #define __bridge_retained
    #endif

    #ifndef __autoreleasing
        #define __autoreleasing
    #endif

    #ifndef __strong
        #define __strong
    #endif

    #ifndef __unsafe_unretained
        #define __unsafe_unretained
    #endif

    #ifndef __weak
        #define __weak
    #endif
#endif

#if __has_feature(objc_arc)
    #define SAFE_ARC_PROP_RETAIN strong
    #define SAFE_ARC_RETAIN(x) (x)
    #define SAFE_ARC_RELEASE(x)
    #define SAFE_ARC_AUTORELEASE(x) (x)
    #define SAFE_ARC_BLOCK_COPY(x) (x)
    #define SAFE_ARC_BLOCK_RELEASE(x)
    #define SAFE_ARC_SUPER_DEALLOC()
    #define SAFE_ARC_AUTORELEASE_POOL_START() @autoreleasepool {
    #define SAFE_ARC_AUTORELEASE_POOL_END() }
#else
    #define SAFE_ARC_PROP_RETAIN retain
    #define SAFE_ARC_RETAIN(x) ([(x) retain])
    #define SAFE_ARC_RELEASE(x) ([(x) release])
    #define SAFE_ARC_AUTORELEASE(x) ([(x) autorelease])
    #define SAFE_ARC_BLOCK_COPY(x) (Block_copy(x))
    #define SAFE_ARC_BLOCK_RELEASE(x) (Block_release(x))
    #define SAFE_ARC_SUPER_DEALLOC() ([super dealloc])
    #define SAFE_ARC_AUTORELEASE_POOL_START() NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    #define SAFE_ARC_AUTORELEASE_POOL_END() [pool release];
#endif
</pre>
<p>These macros come packaged with <a href="https://github.com/ZaBlanc/InnerBand">InnerBand</a>.  In fact, the InnerBand project supports ARC and non-ARC using these same macros.  It serves as an excellent reference of how to use them.</p>
<p>Your mindset should be to use these macros as if you&#8217;re programming with old-fashioned manual memory management.  When you&#8217;re not using ARC, the macros behave as you&#8217;d expect with <i>SAFE_ARC_AUTORELEASE</i> calling <i>autorelease</i> and so on.  When you&#8217;re using ARC, the call is ignored.</p>
<p>The bottom line is you don&#8217;t have to worry about it.  Just use the macros as if you were coding the old way and everything will be taken care of for you. With just a few caveats, of course.</p>
<p>Notice that <i>__bridge_tranfer</i> isn&#8217;t present.  It&#8217;s not something that can simply be ignored in a non-ARC context.  Toll-free bridging is hairy with ARC.  If you use it, I recommend sticking with the <i>__has_feature(objc_arc)</i> check and implementing the ARC and non-ARC completely separately.</p>
<p>Also, there may be some edge cases where you need to copy a block in ARC.  This is done somewhat differently than using <i>Block_copy</i>.  It&#8217;s rare, but know that if there is a problem with not calling the copy, you&#8217;ll know in the form of crashes.  </p>
<h3>Demonstration</h3>
<p>Now I&#8217;ll show you how to use the macros.  You can leave your project as non-ARC or convert it to ARC.  I prefer leaving it as non-ARC, but that&#8217;s just me.  You can even create a second target and have both.  However you do it, just be sure to test both compiled versions of your code before releasing.</p>
<p>Here&#8217;s how you&#8217;d perform an autorelease:</p>
<pre class="brush: objc; title: ; notranslate">
- (User *)userWithName:(NSString *)name {
    return SAFE_ARC_AUTORELEASE([[User alloc] initWithName:name]);
}
</pre>
<p>In non-ARC code, it performs the autorelease.  In ARC code, it simply returns the value.  Note that with this macro if you call <i>SAFE_ARC_AUTORELEASE</i> on a standalone line, you&#8217;ll get a warning that the value is not being used.  In almost all cases, an autorelease is coupled with a return or at the end of an allocation, but if you do get the warning you can simply assign the autorelease back itself like this to fix it:</p>
<pre class="brush: objc; title: ; notranslate">
    myName = SAFE_ARC_AUTORELEASE(myName);
</pre>
<p>Retains and releases are similar to autoreleasing:</p>
<pre class="brush: objc; title: ; notranslate">
- (void)setName:(NSString *)name {
    if (name_ != name) {
        SAFE_ARC_RELEASE(name_);
        name_ = SAFE_ARC_RETAIN(name);
    }

    ...
</pre>
<p>If you like to perform your setters with the three-step idiom (retain, release, set), you&#8217;ll get the same warning you did with <i>SAFE_ARC_AUTORELEASE</i>.  The same fix applies.  If you do the two-step idiom (release, retain with if conditional) as above then you won&#8217;t need to worry.</p>
<p>Blocks don&#8217;t generally need to be copied in ARC.  Here&#8217;s how you&#8217;d handle it in your multi-context code:</p>
<pre class="brush: objc; title: ; notranslate">
- (id)initWithBlock:(void (^)(void))block
    if ((self = [super init])) {
        block_ = SAFE_ARC_BLOCK_COPY(block);
    }

    return self;
}

- (void)dealloc {
    SAFE_ARC_BLOCK_RELEASE(block_);
    SAFE_ARC_SUPER_DEALLOC();
}
</pre>
<p>The above also demonstrates how to call a dealloc on the super class, which is expressly forbidden in ARC.  The code is removed by the compiler when using ARC, but calls [super dealloc] when compiled as older code.</p>
<p>Autorelease pools have changed, too.  Although not strictly necessary, the two different autorelease pool declarations are supported.  When you write code to work within an autorelease pool, wrap it like this:</p>
<pre class="brush: objc; title: ; notranslate">
- (id)complexMethodCall {
    SAFE_ARC_AUTORELEASE_POOL_START();

    ...my code here...

    SAFE_ARC_AUTORELEASE_POOL_END();
}
</pre>
<p>In ARC, there&#8217;s a lot more options for specifying a property.  While <i>assign</i> and <i>copy</i> can still be used, there&#8217;s a newer specifier called strong.  This is essentially retain, so you can write your property like this:</p>
<pre class="brush: objc; title: ; notranslate">
    @property(nonatomic, SAFE_ARC_PROP_RETAIN) User *user;
</pre>
<p>If you want to use any ARC-specific specifiers other than that, you&#8217;ll need to use code compilation with <i>__has_feature(objc_arc)</i> since there are no non-ARC equivalents.</p>
<p>And finally, there&#8217;s Toll-Free Bridging.  This is one area that got more complex in ARC.<br />
I usually resort to code compilation. See the <a href="https://github.com/ZaBlanc/InnerBand">InnerBand</a> code for examples of this surgical procedure.  Luckily, you won&#8217;t use it much unless you&#8217;re using Core Graphics.</p>
<h3>Parting Words</h3>
<p>These macros are not being offered as an alternative to knowing ARC.  On the contrary, you should know ARC before attempting to convert any older code over.  The spirit of these macros is to easily, and cleanly, allow library code to run in either context. If you&#8217;re not feeling so hot on your ARC knowledge, my favorite resources for ARC are  <a href="http://developer.apple.com/library/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/_index.html">Apple&#8217;s ARC Documentation</a>, <a href="http://www.mikeash.com/pyblog/friday-qa-2011-09-30-automatic-reference-counting.html">Mike Ash</a>, and a <a href="http://www.learn-cocos2d.com/2011/11/everything-know-about-arc/">hidden gem</a> from the maker of Kobold2D.</p>
]]></content:encoded>
			<wfw:commentRss>http://raptureinvenice.com/arc-support-without-branches/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Started with Mogenerator</title>
		<link>http://raptureinvenice.com/getting-started-with-mogenerator/</link>
		<comments>http://raptureinvenice.com/getting-started-with-mogenerator/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 02:07:52 +0000</pubDate>
		<dc:creator>John Blanco</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[mogenerator]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://raptureinvenice.com/?p=464</guid>
		<description><![CDATA[If you&#8217;re an iOS developer using Core Data in your app, whether a n00b or expert, you should be using Mogenerator. I mean, really, you *should* be using it. If you don&#8217;t, well don&#8217;t worry, I&#8217;m not only going to tell you why you need it, I&#8217;m including a tutorial on how to use it! [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re an iOS developer using Core Data in your app, whether a n00b or expert, you should be using <a href="https://github.com/rentzsch/mogenerator#readme">Mogenerator</a>.  I mean, really, you *should* be using it. If you don&#8217;t, well don&#8217;t worry, I&#8217;m not only going to tell you why you need it, I&#8217;m including a tutorial on how to use it!</p>
<p>So let&#8217;s get to it!</p>
<h3>I know Core Data already, so why do I need Mogen?</h3>
<p>Core Data is a huge beast of a thing.  There&#8217;s so much to know, and you&#8217;re not going to get any new functionality from Mogen either.  What you *will* get, however, is a Core Data that will be far, far easier to use.  This is what Mogen does for you:</p>
<ol>
<li>Faster and easier generation of concrete classes for your model.
<li>A proper two-class treatment in that generation.</li>
<li>Alleviates the need to wrap numeric attributes in NSNumber objects.</li>
<li>Handy setter methods for manipulating sets easily.</li>
<li>Handy wrapper methods for insertion/entity identification.
</ol>
<p>I can&#8217;t wait to get into it all, but first you need to install Mogen and set up your project!</p>
<h3>Installation</h3>
<p>The first thing you&#8217;ll need to do is install Mogen.  It&#8217;s simple, you <a href="http://rentzsch.github.com/mogenerator/">install Mogen from a DMG</a>. After this one-time step, we&#8217;ll now configure your project to use it:</p>
<ol>
<li>In your project, open your project properties and click &#8220;Add Target&#8221;.<br /><a href="http://raptureinvenice.com/wp-content/uploads/2012/01/Screen-Shot-2012-01-22-at-6.02.40-PM.png"><img class="alignleft size-medium wp-image-467" title="Screen Shot 2012-01-22 at 6.02.40 PM" src="http://raptureinvenice.com/wp-content/uploads/2012/01/Screen-Shot-2012-01-22-at-6.02.40-PM-300x164.png" alt="" width="300" height="164" /></a><br clear="all">
<p></p>
</li>
<li>Add an &#8220;Aggregate&#8221; target (you&#8217;ll find it in the Other grouping). Hit Next.</li>
<li>Name the target whatever you&#8217;d like. I&#8217;ll call mine <em>Mogenerator</em>. Hit Done.<a href="http://raptureinvenice.com/wp-content/uploads/2012/01/Screen-Shot-2012-01-22-at-6.14.58-PM1.png"><img src="http://raptureinvenice.com/wp-content/uploads/2012/01/Screen-Shot-2012-01-22-at-6.14.58-PM1-300x47.png" alt="" title="Screen Shot 2012-01-22 at 6.14.58 PM" width="300" height="47" class="alignleft size-medium wp-image-479" /></a><br clear="all"/>
<p></p>
</li>
<li>Now select the new target you just created and click &#8220;Add Build Phase&#8221; then &#8220;Add Run Script&#8221;.</li>
<li>Open the Run Script group that just appeared and enter in the information as you see it below while adjusting the names to match your own project.  Feel free to modify it to fit your own needs, perhaps to create your model files in a subdirectory.<br /><a href="http://raptureinvenice.com/wp-content/uploads/2012/01/Screen-Shot-2012-01-22-at-6.23.54-PM.png"><img src="http://raptureinvenice.com/wp-content/uploads/2012/01/Screen-Shot-2012-01-22-at-6.23.54-PM-300x150.png" alt="" title="Screen Shot 2012-01-22 at 6.23.54 PM" width="300" height="150" class="alignleft size-medium wp-image-480" /></a><br clear="all"/></li>
<li>When you create entities in your data model, be sure to populate the &#8220;Class&#8221; field with the same name as the entity. (You can name it whatever you want, actually, but that would be mighty stupid to do.)<br /><a href="http://raptureinvenice.com/wp-content/uploads/2012/01/Screen-Shot-2012-01-22-at-6.26.58-PM.png"><img src="http://raptureinvenice.com/wp-content/uploads/2012/01/Screen-Shot-2012-01-22-at-6.26.58-PM.png" alt="" title="Screen Shot 2012-01-22 at 6.26.58 PM" width="256" height="110" class="alignleft size-full wp-image-481" /></a></ol>
<p><br clear="all" /><br />
Now, we&#8217;re all ready to go, but what did we win?  I&#8217;ll outline that next.</p>
<h3>Faster, Improved Class Generation</h3>
<p>I&#8217;ve been programming iPhone apps for almost 3 years now and, I&#8217;ll be honest, I still can&#8217;t tell you the exact steps to generate Core Data classes.  It seems to involve selecting the right entities in the model, adding a new file, and changing some checkbo &#8212; look, I don&#8217;t know.  I think they made it a little easier recently, but it was crazy and I use Mogen now so I don&#8217;t care anymore. <img src='http://raptureinvenice.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />   All I know is it&#8217;s much easier now.</p>
<p>Change your build target to &#8220;Mogenerator&#8221; (or whatever you called it) and hit ⌘B to build.  <strong>And you&#8217;re done.</strong> At this point, since you generated new files, you&#8217;ll need to add them to your project.  You won&#8217;t have to do this on future regenerations, but for new entities, yes.</p>
<p>You&#8217;ll notice that there are two sets of files, _Event.* and Event.*.  If you&#8217;re not familiar with this pattern, it&#8217;s <em>amazing</em>.  It&#8217;s also been used for years and <strong>shame</strong> on Apple that they don&#8217;t do this out of the box.  The _Event.* files are generated and <em>you should never touch them</em>.  The Event.* files are generated only if they don&#8217;t exist and you can feel free to add any  methods and properties you like.</p>
<p>Yes, that&#8217;s right, gone are the days where you avoided adding methods to your concrete classes knowing that once you did you wouldn&#8217;t be able to generate them anymore.  Add all you want, now! The clean coding gods will thank you!</p>
<p>From here on out, whenever you change your model, regenerate the classes, rinse and repeat.</p>
<h3>Better Setters</h3>
<p>Maybe I&#8217;m alone, but early on one of the mistakes I made over and over again was to forget that my numeric entity attributes were wrapped in NSNumber.  I&#8217;d constantly write code like this:</p>
<pre class="brush: objc; title: ; notranslate">
if (user.isAdmin) {
    ...
}
</pre>
<p>WRONG!  The isAdmin attribute is an NSNumber, so this will evaluate to true for all cases where isAdmin isn&#8217;t nil!  I ran into this so many times I even contemplated scrapping Core Data to erase the emotional pain.</p>
<p>Not anymore with Mogen.  You can now write the code as:</p>
<pre class="brush: objc; title: ; notranslate">
if (user.isAdminValue) {
    ...
}
</pre>
<p>This simple upgrade is a godsend!  Setting attributes is equally easy, and you get to keep the original setters and getters to boot.  You can use whatever is useful at the moment.  With some attributes, I&#8217;ll use both versions:</p>
<p>Thank you, thank you Mogen!</p>
<h3>Even More Useful Methods</h3>
<p>Aside from the setters and getters, you get some useful methods for relationships, too.  Now, I believe Apple has learned their lesson and now provide similar methods like these, but too little, too late.  So, let&#8217;s say for example you have a entities named <em>User</em> and <em>Role</em> with a to-many relationship on <em>User</em> named <em>roles</em>.  You can write code like this to add a role to the user:</p>
<pre class="brush: objc; title: ; notranslate">
User *user = [User insertInManagedObjectContext:moc];
user.name = @&quot;John Blanco&quot;;

Role *role = [Role insertInManagedObjectContext:moc];
role.type = @&quot;Administrator&quot;;

[user addRolesObject:role];
</pre>
<p>And you&#8217;re done.  No need to create a mutable set or anything, it&#8217;s all handled for you.  There&#8217;s a handful of other methods like this, one that lets you remove an object and two more that let you add or remove multiples objects in a set.</p>
<h3>Validations, Too!</h3>
<p>Mind you, this isn&#8217;t a Mogen thing.  This is a Core Data thing.  Validations let you test your data before saving to your persistant store.  But, you might not even have known this existed!  This is because you have to specify your validations in the concreate class and, if you&#8217;re not using Mogen, you&#8217;d have to keep rewriting them every time you regenerated your classes.  WHAT?!</p>
<p>Now, you can specify validations like this:</p>
<pre class="brush: objc; title: ; notranslate">
- (BOOL)validateEmail:(id *)value error:(NSError **)error {
    if (self.email &amp;&amp; ![self.email isValidEmailAddress] &amp;&amp; error) {
        *error = [NSError errorWithDomain:@&quot;MyErrorDomain&quot; code:1];
        return NO;
    }

    return YES;
}
</pre>
<p>This is how you validate individual attributes, but there are other hooks available. Find out more about <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdValidation.html">Core Data Validations</a> to harness even more power.</p>
<h3>Conclusion</h3>
<p>I hope I&#8217;ve made my case for Mogenerator.  It&#8217;s an invaluable tool!  It simplifies anything and since I learned about it I haven&#8217;t worked on a project without it.  Even better, since it&#8217;s a tool and not a library, it interoperates perfectly with other Core Data libraries like <a href="https://github.com/ZaBlanc/InnerBand">InnerBand&#8217;s Core Data Store</a> and <a href="https://github.com/magicalpanda/MagicalRecord">Magical Record</a>.</p>
<p>Now go forth, young soldier!</p>
]]></content:encoded>
			<wfw:commentRss>http://raptureinvenice.com/getting-started-with-mogenerator/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.864 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-04-05 00:11:51 -->

