<?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>Tap Tapas Blog &#171; iPhone, iPad and iPod touch App Development</title>
	<atom:link href="http://www.taptapas.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.taptapas.com/blog</link>
	<description></description>
	<lastBuildDate>Fri, 16 Mar 2012 15:11:04 +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>A St. Paddy&#8217;s Worth&#160;Sharing</title>
		<link>http://www.taptapas.com/blog/ishots-st-patricks-day-updated/</link>
		<comments>http://www.taptapas.com/blog/ishots-st-patricks-day-updated/#comments</comments>
		<pubDate>Fri, 16 Mar 2012 14:35:52 +0000</pubDate>
		<dc:creator>tap tapas</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.taptapas.com/blog/?p=393</guid>
		<description><![CDATA[This 17h of March we&#8217;re shaking things up with a throwback to throw back. iShots &#8211; St. Paddy&#8217;s is coming back off the shelf with 400% more pixels (by volume) and a new twist for the social drinker. Entertain your Twitter followers and embarrass your Facebook friends by sharing your favorite iShots straight up or [...]]]></description>
			<content:encoded><![CDATA[<p>This 17h of March we&#8217;re shaking things up with a throwback to throw back.</p>
<p><a href="http://ishots.taptapas.com">iShots &#8211; St. Paddy&#8217;s</a> is coming back off the shelf with 400% more pixels (by volume) and a new twist for the social drinker.</p>
<p>Entertain your Twitter followers and embarrass your Facebook friends by sharing your favorite iShots straight up or paired with the photos you won&#8217;t remember you took.</p>
<p>Enjoy new toasts, more mixing directions and crisp Retina graphics with 2x the resolution, 3x the file size and 4x the likelihood someone will mistakingly set their drink on your phone.</p>
<p><a href="http://t.co/rqilKmf">Get the app</a>, drink responsibly and have yourself a St. Patricks Day worth sharing.</p>
<div id="attachment_415" class="wp-caption aligncenter" style="width: 210px"><img class="size-full wp-image-415" title="Share your St Patrick's day" src="http://www.taptapas.com/blog/wp-content/uploads/2012/03/ishots-rereleased.gif" alt="" width="200" height="227" /><p class="wp-caption-text">Share your St Patrick's day</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.taptapas.com/blog/ishots-st-patricks-day-updated/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loading CoreData using&#160;Python</title>
		<link>http://www.taptapas.com/blog/loading-coredata-using-python/</link>
		<comments>http://www.taptapas.com/blog/loading-coredata-using-python/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 11:12:19 +0000</pubDate>
		<dc:creator>tap tapas</dc:creator>
				<category><![CDATA[Tech Talk]]></category>

		<guid isPermaLink="false">http://www.taptapas.com/blog/?p=250</guid>
		<description><![CDATA[When we started using CoreData in apps it became clear some would benefit from having data preloaded into a CoreData sqlite file. This file could be added to the app bundle and could be copied to the apps Documents folder on first use. However when it came to setting up the project to do this it brought some challenges...]]></description>
			<content:encoded><![CDATA[<p>CoreData is one of the iOS features that I have come to value and use in almost every client project we have undertaken. Combined with the design tools in Xcode it provides a very powerful layer to hide the complexities of database development in a language such as Objective-C. It makes working with complex persistent data structures much easier.</p>
<p>When we started using CoreData in apps it became clear some would benefit from having data preloaded into a CoreData sqlite file. This file could be added to the app bundle and could be copied to the apps Documents folder on first use. However when it came to setting up the project to do this it brought some challenges.</p>
<p>Because the underlying storage is managed by CoreData it raises the question of how do you preload data into the CoreData sqlite store? The internal structure is CoreData’s responsibility. Whilst you can look directly into the sqlite file and deduce its layout to use with some sqlite data loading tools this is far from ideal. Can you be sure you have things correct or that some future release of CoreData won’t change things?</p>
<p>It seems that the sensible approach is to use CoreData itself to write your initial data into the file. This led me to consider the following approaches:</p>
<p>Write some initialization code into the app to read data from some other file and create the CoreData entities from this. The app can then run this code when it is first used to setup the data. However this is not ideal because it could result in a long launch time for the user the first time they run the app. As an example the post code data example below took over a minute to load using this approach on an iPhone 3GS. That is not something a we or an end user would accept.</p>
<p>Write an OS X utility to load the data on your build system. This could then be run periodically to create the sqlite data file for the model. However this means writing a separate ObjC utility and maintaining the code as the model changes through development. Such a utility could be setup as a sub target in the main apps project. It could even share some source code for the model but its still more effort than I’d like. Also I found that Xcode at the time (and it may still be the case) had issues with sub-targets with different platforms. For this approach I found I could use the utility as a tool within the main project but not automate its recreation as needed as part of the main build.</p>
<p>I’ve used python at various points in my career but had not looked closely at the PyObjC bindings available in OS X. However, around this time I was reminded of the technology. PyObjC is a bridging layer that allows access to Cocoa/Foundation frameworks directly from python scripts. So I got thinking, can I drive CoreData from Python? After some experimentation it turns out the answer is yes. Armed with this new approach I was able to write a Python script and run it as part of the iOS build through the command shell build step feature of Xcode. Dependencies could also be setup on the Python script files, the sqlite store file output by the script and any data input files you may want to use. With dependencies correctly configured the script runs at the correct point in the build process and only when it needs to.</p>
<p>In addition Python provides many high level modules for handling csv, xml, various database formats, or you cold even pull data from the apps web service. This is something we have used so the build process automatically include the current data from an associated web service into the target app.</p>
<p>As an example consider we have a post code CSV file with UK post codes and their corresponding GPS coordinates. We want this data loaded into a CoreData store that can be embedded into an app. The Python script in Fig 1 below, importer.py, will do just that. The entity ‘Postcode’ in this example has three attributes ‘postcode’, ‘latitude’ and ‘longitude’. The script takes three input arguments, the path to the object model file, the path to location to write the resulting CoreData store and the post code input csv file.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
</pre></td><td class="code"><pre class="python" style="font-family:monospace;color: #FCFFBA;"><span style="color: #808080; font-style: italic;color: #CDC;">#!/usr/bin/python2.6</span>
&nbsp;
<span style="color: #808080; font-style: italic;color: #CDC;"># Import frameworks</span>
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">from</span> CoreData <span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> <span style="color: #66cc66;color: #CCC;">*</span>
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">from</span> Foundation <span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> <span style="color: #66cc66;color: #CCC;">*</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> <span style="color: #dc143c;color: #8FB394;">sys</span>,<span style="color: #dc143c;color: #8FB394;">os</span>
&nbsp;
<span style="color: #808080; font-style: italic;color: #CDC;"># MOLoader is a python classed derived from NSManagedObject. It takes an</span>
<span style="color: #808080; font-style: italic;color: #CDC;"># entity name, managed object context and dictionary of key/value pairs</span>
<span style="color: #808080; font-style: italic;color: #CDC;"># and instantiates an instance of the entity within the context and</span>
<span style="color: #808080; font-style: italic;color: #CDC;"># sets the key/value pairs.</span>
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">class</span> MOLoader<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span>NSManagedObject<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>:
&nbsp;
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> initWithEntityNamed_inManagedObjectContext_withDictionary_<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #008000;color: #577A61;">self</span>, entityName, moc, data<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>:
        entity = NSEntityDescription.<span style="color: #d9d9d9;color: #d9d9d9;">entityForName_inManagedObjectContext_</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span>entityName, moc<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
        <span style="color: #008000;color: #577A61;">self</span> = <span style="color: #008000;color: #577A61;">super</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span>MOLoader, <span style="color: #008000;color: #577A61;">self</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>.<span style="color: #d9d9d9;color: #d9d9d9;">initWithEntity_insertIntoManagedObjectContext_</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span>entity, moc<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;color: #B83A24;">if</span> <span style="color: #008000;color: #577A61;">self</span> <span style="color: #ff7700;font-weight:bold;color: #B83A24;">is</span> <span style="color: #008000;color: #577A61;">None</span>:
            <span style="color: #ff7700;font-weight:bold;color: #B83A24;">return</span> <span style="color: #008000;color: #577A61;">None</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;color: #B83A24;">for</span> key <span style="color: #ff7700;font-weight:bold;color: #B83A24;">in</span> data.<span style="color: #d9d9d9;color: #d9d9d9;">keys</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>:
            <span style="color: #008000;color: #577A61;">self</span>.<span style="color: #d9d9d9;color: #d9d9d9;">setValue_forKey_</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span>data<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#91;</span>key<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#93;</span>, key<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;color: #B83A24;">return</span> <span style="color: #008000;color: #577A61;">self</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">if</span> __name__ == <span style="color: #483d8b;color: #666666;">'__main__'</span>:
&nbsp;
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">'Using Managed Object Model'</span>, <span style="color: #dc143c;color: #8FB394;">sys</span>.<span style="color: #d9d9d9;color: #d9d9d9;">argv</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#91;</span><span style="color: #ff4500;color: #DDD;">1</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">'Input data'</span>, <span style="color: #dc143c;color: #8FB394;">sys</span>.<span style="color: #d9d9d9;color: #d9d9d9;">argv</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#91;</span><span style="color: #ff4500;color: #DDD;">3</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">'Creating CoreData file'</span>, <span style="color: #dc143c;color: #8FB394;">sys</span>.<span style="color: #d9d9d9;color: #d9d9d9;">argv</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#91;</span><span style="color: #ff4500;color: #DDD;">2</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#93;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;color: #CDC;"># Load model</span>
    bundle = NSBundle.<span style="color: #d9d9d9;color: #d9d9d9;">bundleWithPath_</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #dc143c;color: #8FB394;">sys</span>.<span style="color: #d9d9d9;color: #d9d9d9;">argv</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#91;</span><span style="color: #ff4500;color: #DDD;">1</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#93;</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
    bundleArray = NSArray.<span style="color: #d9d9d9;color: #d9d9d9;">arrayWithObject_</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span>bundle<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
&nbsp;
    mom = NSManagedObjectModel.<span style="color: #d9d9d9;color: #d9d9d9;">alloc</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>.<span style="color: #d9d9d9;color: #d9d9d9;">initWithContentsOfURL_</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span>NSURL.<span style="color: #d9d9d9;color: #d9d9d9;">fileURLWithPath_</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #dc143c;color: #8FB394;">sys</span>.<span style="color: #d9d9d9;color: #d9d9d9;">argv</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#91;</span><span style="color: #ff4500;color: #DDD;">1</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#93;</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">if</span> mom <span style="color: #ff7700;font-weight:bold;color: #B83A24;">is</span> <span style="color: #008000;color: #577A61;">None</span>:
        <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">&quot;Unable to load model&quot;</span>
        <span style="color: #dc143c;color: #8FB394;">sys</span>.<span style="color: #d9d9d9;color: #d9d9d9;">exit</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #ff4500;color: #DDD;">1</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;color: #CDC;"># Setup persistent store</span>
    urlForDb = NSURL.<span style="color: #d9d9d9;color: #d9d9d9;">fileURLWithPath_</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #dc143c;color: #8FB394;">sys</span>.<span style="color: #d9d9d9;color: #d9d9d9;">argv</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#91;</span><span style="color: #ff4500;color: #DDD;">2</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#93;</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
    psc = NSPersistentStoreCoordinator.<span style="color: #d9d9d9;color: #d9d9d9;">alloc</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>.<span style="color: #d9d9d9;color: #d9d9d9;">initWithManagedObjectModel_</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span>mom<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
    ps = psc.<span style="color: #d9d9d9;color: #d9d9d9;">addPersistentStoreWithType_configuration_URL_options_error_</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span>NSSQLiteStoreType,<span style="color: #008000;color: #577A61;">None</span>,
        urlForDb, <span style="color: #008000;color: #577A61;">None</span>, <span style="color: #008000;color: #577A61;">None</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">if</span> ps<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#91;</span><span style="color: #ff4500;color: #DDD;">0</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#93;</span> <span style="color: #ff7700;font-weight:bold;color: #B83A24;">is</span> <span style="color: #008000;color: #577A61;">None</span>:
        <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> ps<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#91;</span><span style="color: #ff4500;color: #DDD;">1</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#93;</span>.<span style="color: #d9d9d9;color: #d9d9d9;">description</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
        <span style="color: #dc143c;color: #8FB394;">sys</span>.<span style="color: #d9d9d9;color: #d9d9d9;">exit</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #ff4500;color: #DDD;">1</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
&nbsp;
    moc = NSManagedObjectContext.<span style="color: #d9d9d9;color: #d9d9d9;">alloc</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>.<span style="color: #d9d9d9;color: #d9d9d9;">init</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
    moc.<span style="color: #d9d9d9;color: #d9d9d9;">setPersistentStoreCoordinator_</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span>psc<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;color: #CDC;"># Import postcodes</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">'Adding postcodes'</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">for</span> line <span style="color: #ff7700;font-weight:bold;color: #B83A24;">in</span> <span style="color: #008000;color: #577A61;">open</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #dc143c;color: #8FB394;">sys</span>.<span style="color: #d9d9d9;color: #d9d9d9;">argv</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#91;</span><span style="color: #ff4500;color: #DDD;">3</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#93;</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>.<span style="color: #d9d9d9;color: #d9d9d9;">readlines</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>:
        columns = line.<span style="color: #d9d9d9;color: #d9d9d9;">split</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #483d8b;color: #666666;">','</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
        lat = <span style="color: #008000;color: #577A61;">float</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span>columns<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#91;</span><span style="color: #ff4500;color: #DDD;">1</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#93;</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
        lng = <span style="color: #008000;color: #577A61;">float</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span>columns<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#91;</span><span style="color: #ff4500;color: #DDD;">2</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#93;</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> columns<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#91;</span><span style="color: #ff4500;color: #DDD;">0</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#93;</span>,lat,lng
        MOLoader.<span style="color: #d9d9d9;color: #d9d9d9;">alloc</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>.<span style="color: #d9d9d9;color: #d9d9d9;">initWithEntityNamed_inManagedObjectContext_withDictionary_</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #483d8b;color: #666666;">'Postcode'</span>,moc,
            <span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#123;</span><span style="color: #483d8b;color: #666666;">'postcode'</span>:columns<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#91;</span><span style="color: #ff4500;color: #DDD;">0</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#93;</span>, <span style="color: #483d8b;color: #666666;">'latitude'</span>:lat, <span style="color: #483d8b;color: #666666;">'longitude'</span>:lng<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#125;</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;color: #CDC;"># Save to persistent store</span>
    result = moc.<span style="color: #d9d9d9;color: #d9d9d9;">save_</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #008000;color: #577A61;">None</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">if</span> <span style="color: #ff7700;font-weight:bold;color: #B83A24;">not</span> result<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#91;</span><span style="color: #ff4500;color: #DDD;">0</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#93;</span>:
        <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> result<span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#91;</span><span style="color: #ff4500;color: #DDD;">1</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#93;</span>.<span style="color: #d9d9d9;color: #d9d9d9;">description</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span>
        <span style="color: #dc143c;color: #8FB394;">sys</span>.<span style="color: #d9d9d9;color: #d9d9d9;">exit</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#40;</span><span style="color: #ff4500;color: #DDD;">1</span><span style="color: #d9d9d9;color: #CCC;color: #d9d9d9;">&#41;</span></pre></td></tr></table></div>

<p class="wp-caption-text">Fig 1 &#8211; importer.py</p>
<p>Now we have a script, its just a case of adding it to the project. Make sure its not included as target member otherwise it will be copied into the app bundle (same applies to any source data files used by the script). To setup the script add a ‘Run Script’ build phase and configure along the lines shown in Fig 2.</p>
<div id="attachment_323" class="wp-caption aligncenter" style="width: 504px"><img class="size-large wp-image-323" title="Xcode Script Build Phase Configuration" src="http://www.taptapas.com/blog/wp-content/uploads/2012/02/Xcode1-494x610.jpg" alt="" width="494" height="610" /><p class="wp-caption-text">Fig 2 – Example script build phase to run python script</p></div>
<p>I hope this technique is of use and would be interested to hear how others are setting up CoreData files to bundle in their apps. I have found it provides a quick high level means to pre-load data into CoreData from a wide range of input sources. The example is very simple but the concept can be greatly expanded upon for more complex models and data requirements.</p>
<p>Here is a simple Xcode project based on the example discussed.</p>
<p><a href="http://www.taptapas.com/blog/wp-content/uploads/2012/02/Postcodes-Xcode-Project.zip">Example Xcode Project</a></p>
<p>Finally here are a couple of references to PyObjC.</p>
<p><a href="http://pyobjc.sourceforge.net/">http://pyobjc.sourceforge.net/</a><br />
<a href="https://developer.apple.com/cocoa/pyobjc.html">https://developer.apple.com/cocoa/pyobjc.html</a></p>
<p>Mark Woollard<br />
CTO Tap Tapas LLC</p>
]]></content:encoded>
			<wfw:commentRss>http://www.taptapas.com/blog/loading-coredata-using-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mock&#160;Draft Giveaway</title>
		<link>http://www.taptapas.com/blog/2011-mock-draft-giveaway/</link>
		<comments>http://www.taptapas.com/blog/2011-mock-draft-giveaway/#comments</comments>
		<pubDate>Wed, 26 Jan 2011 15:47:20 +0000</pubDate>
		<dc:creator>tap tapas</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Jordan]]></category>

		<guid isPermaLink="false">http://www.taptapas.com/blog/?p=237</guid>
		<description><![CDATA[Announcing the 2011 Mock Draft Giveaway from Tap Tapas! Mock Draft is the only application for iPhone and iPod Touch that gives the user the chance to play as General Manager of any team in the upcoming NFL Draft. Ten lucky contestants will receive Mock Draft FREE this year in the Mock Draft Giveaway. With [...]]]></description>
			<content:encoded><![CDATA[<p>Announcing the 2011 Mock Draft Giveaway from Tap Tapas!</p>
<p>Mock Draft is the only application for iPhone and iPod Touch that gives the user the chance to play as General Manager of any team in the upcoming NFL Draft. Ten lucky contestants will receive Mock Draft FREE this year in the Mock Draft Giveaway.</p>
<p>With Mock Draft you&#8217;ll scout the best college football players and make your selections for the NFL season. See all the latest stats, including results from the Scouting Combine in Indianapolis and updates from Pro Day workouts. You can even watch highlights and game film, all from your iPhone or iPod touch! Mock Draft puts you in charge of your own War Room and lets you scout the top 350 draft prospects with continually updated player information and statistics.</p>
<p>To sign up for your chance to win a free download of Mock Draft (normally $2.99) just <a href="http://www.taptapas.com/about_and_contact.php#contact_us" style="white-space:nowrap;">send us a message</a> with your name, contact information and the answer to the following question:</p>
<p><strong>&#8220;What was the name of the first fantasy football league ever created&#8221;</strong></p>
<p>First ten correct answers will receive Mock Draft for free!<br />
Results will be announced here in a few days.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.taptapas.com/blog/2011-mock-draft-giveaway/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MC 335 &#8211; Designing Mobile&#160;Experiences</title>
		<link>http://www.taptapas.com/blog/mc-335-designing-mobile-experiences/</link>
		<comments>http://www.taptapas.com/blog/mc-335-designing-mobile-experiences/#comments</comments>
		<pubDate>Thu, 23 Sep 2010 17:35:47 +0000</pubDate>
		<dc:creator>tap tapas</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.taptapas.com/blog/?p=234</guid>
		<description><![CDATA[Michael DeSouza and Justin Velgos of Tap Tapas to teach a course at Maine College of Art &#8211; Designing Mobile Experiences. The objective of this course is to conceptualize and design a touch-screen mobile application. Students will work in teams to research, explore and present their ideas for critique. The most viable concept will be [...]]]></description>
			<content:encoded><![CDATA[<p>Michael DeSouza and Justin Velgos of Tap Tapas to teach a course at Maine College of Art &#8211; Designing Mobile Experiences.</p>
<p>The objective of this course is to conceptualize and design a touch-screen mobile application. Students will work in teams to research, explore and present their ideas for critique. The most viable concept will be chosen and submitted to Kickstarter.com. If the kickstarter project receives funding, their app will be built and submitted to the App Store by Tap Tapas.  Each student will get a share of any profit it generates.</p>
<p>Follow the progress on the <a href="http://mc335.taptapas.com/">MC 335 </a>blog or on the <a href="http://mc335students.tumblr.com/">student blog.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.taptapas.com/blog/mc-335-designing-mobile-experiences/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parking Mate featured by iTunes App&#160;Store</title>
		<link>http://www.taptapas.com/blog/parking-mate-featured-by-itunes-app-store/</link>
		<comments>http://www.taptapas.com/blog/parking-mate-featured-by-itunes-app-store/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 19:41:26 +0000</pubDate>
		<dc:creator>tap tapas</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.taptapas.com/blog/?p=215</guid>
		<description><![CDATA[iTunes App Store on Facebook: App Store really doesn’t want another parking ticket. Parking Mate can help you avoid tickets, towing, and other parking restrictions. And it’s free. Compatible with iPhone, iPod touch, and iPad, Parking Mate allows you to set a meter timer, add locations and street rules, see which of your locations are [...]]]></description>
			<content:encoded><![CDATA[<p>iTunes App Store on Facebook:</p>
<blockquote><p><strong>App Store really doesn’t want another parking ticket.</strong></p>
<p>Parking Mate can help you avoid tickets, towing, and other parking restrictions. And it’s free.</p>
<p>Compatible with iPhone, iPod touch, and iPad, Parking Mate allows you to set a meter timer, add locations and street rules, see which of your locations are safe for parking, and reminds you to move your car.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.taptapas.com/blog/parking-mate-featured-by-itunes-app-store/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
