Posted on Aug 17, 2011

Automatically update store schema with Core Data

Today I was playing with Core Data technology and I was trying to check whether it is possible to update the store schema according to the changes I made to the entities, relationships and whatever else.

I found out that the important steps are:

  • Use the versioning: before modifying your current schema you should select “Editor -> Add Model Version..”
  • Edit as much as you like
  • Select the new version as the active one
  • Go to your app delegate file and modify the - (NSPersistentStoreCoordinator *) persistentStoreCoordinator method as follows:
    NSURL *url = [applicationFilesDirectory URLByAppendingPathComponent:@"YourApp.storedata"];
        __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom];
    
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
    						 [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
    						 [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
    
    if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:options error:&error]) {
    		// The rest of the code here
    	}
    
    return __persistentStoreCoordinator;
    



    The highlighted lines are the one to be added. Please notice that row 8 needs to be updated with options:options. I only tried it using NSSQLiteStoreType as persistent store type but it should work fine even with NSXMLStoreType.

References:

  1. Working with Core Data: Schema Versioning and Lightweight Migrations

Posted on May 1, 2011

Free over-the-air distribution

Few days ago, Matteo Kuzeko, pointed out to my attention a web service that easily allows iOS developers to share they own application over-the-air in order to do beta testing: TestFlight

In my previous related post I briefly told you how to do the same all by yourself; with TestFlight the goal is the same but this service brings altogether few interesting features. Practically speaking, you have to build up a Team. The latter is usually composed by the developers and the testers.
With the online control-panel you can invite people by using their email addresses (one at a time) or you can generate an URL to send to all of them an invitation to join the beta testing.

Once your teammates subscribe to the website, they will have to register their devices as well. Once they do that, the developers have to add their device to the list of “compatible” devices. This step is required only the first time you set up the team.

The cool features that TestFlight brings are the instant report of what’s going on in the team (it displays the status of all the teammates and what they did so far) and it sends notifications every time the developers deploy (and hence upload) a new version of the app. This way the mates are automatically notified by the system.

I found it to be very interesting and quite immediate and I will definitively propose it to my team in the next days.

Posted on Sep 7, 2010

Synchronize contacts and calendar between Linux, Mac OS X, iPhone and Nokia

Yeah!
Are you wondering if there’s a way to do such a thing? Yes, there is.
It’s a bit complicated, but not-so-much complicated, and here’s a definitive solution for your problem.

Let’s start saying that I managed to do that using Google Contacts (this link is a bit messy, you can reach a similar page through gMail’s homepage and by clicking “Contacts” on the left sidebar) and Google Calendar. Of course you’ll need a gMail account otherwise everything explained below won’t work.
Second thing I use a Nokia E52 that’s running Symbian 3rd FP2 that I am sure it supplies a Synchronize application that I can find in MenuControl panelPhoneSynchronization (this is a bare translation from Italian, that’s my native language: MenuPannello di controlloTelefonoSincronizzazione.
Third requirement is an account on Goosync. It’s completely free and you need to do that only if you’re going to sync the calendar. Yeah, you got it right: you don’t need Goosync if you’re going to sync only your contacts.

Well, I think we are all set: let’s start configuring those.

First of all make sure you have a backup of your contacts/agenda. That’s important because it’s aleatory the fact that the data are going to be pulled from the server rather than pushed. If the latter occurs, you’re busted.
Once your contacts are ready and set, you can sync those between the system using:

Linux / Mac OS X
Thunderbird: Use Zindus as I wrote in my previous blogpost
Mutt: Use Goobook

Mac OS X
Mail: Open the Address Book application and, in preferences, set to sync your account data using a Google account

iPhone
Just sync it with iTunes. Unfortunately I don’t know if there’s a “mobile” solution, never dug too much into it.

Nokia
Open the Synchronization application I reported above. Create a new profile and name it as you like, let’s say Google.
Then issue the following parameters:

  • Server version: 1.2
  • Server ID: Google
  • Data transport type: Internet
  • Network connection: As you wish (you can use WiFi or 3g, it’s up to you).
  • Host address: https://m.google.com/syncml
  • Port: 443
  • Username: your_gmail_account_@_gmail_dot_com
  • Password: I think you know that
  • Sync type: Both ways

Than, in address book settings (inside the application, don’t quit it), choose

  • Phone database: C:Contacts.db (but before modifying it please have a test with the default setting)
  • Address book database: contacts

Please double check your settings and make sure that you’ve entered then as I wrote: they are case-sensitive

Once your settings are working, please be aware of the following thing: sync works both ways but it’s not 100% reliable. In fact, sometimes, might happen that you delete a contact, it reappears because you had it in your address book on some old machine and then you have to delete that again. Or it may happen that there are conflicts you have to fix.
It’s not to scare the hell out of you, it’s just to say that it’s better if you keep a backup somewhere safe before doing invasive operation on those.

That’s fine, let’s move forward to the Calendar.

It works like the previous one, except that I haven’t tried to find a solution on Linux, yet.
So, let’s signup to Goosync and, if you follow the instructions on their site, you don’t need to issue the following stuff: it’s enough for you to switch profile to the new Goosync.com (in the same Synchronization application).
However, for the manual kind-of-guy (like me), create a new profile and name it as you like.
Enter the following parameters:

  • Server version: 1.2
  • Server ID: SyncWiseEnterprise
  • Data transport type: Internet
  • Network connection: As you wish (you can use WiFi or 3g, it’s up to you).
  • Host address: http://sync2.goosync.com
  • Port: 80
  • Username: your_goosync_username_here
  • Password: your_password_on_goosync
  • Sync type: Both ways

and, again, go to the Calendar settings and set the database to Calendar.

For what concerns Mac OS X, it’s enough for you to use iCal and, in the preferences, create an account and point it to the Google Calendar account. Make sure you deselect all the local calendars or you’re going to freak out.
iPhone applies to the same rule aforementioned: use iTunes and sync everything with it.

As you have might already understand, the limits given by this solution are:

  • You have to manually sync the data on the phone: good for people that don’t want the phone to start sending data while they’re outside, bad for people that commit a lot of changes to their contact’s list or have tons of appointments.
  • You have to manually switch between the two profiles: pain in the ass for the same above reasons. Of course you can buy a Premium account at Goosync website and then you can share contacts and calendar using the same profile.

Posted on Jul 20, 2010

MapKitDynRoutes: Handle iOS4 routes dynamically

Since iPhone iOS4 has released I’ve been working on the new features brought by the new version of the OS.
One of the most useful thing (to me) introduced by iOS4 is the capability of drawing routes directly on the map using public APIs.
How that works is fairly simple: given two or more coordinates it generates a Polyline and put it on the map. This line automagically rescales/resizes in order to maintain the correct aspect even when zooming/panning.

Unfortunately, this new object doesn’t allow developers to update the line with new points. The only thing you can do is to destroy the line, remove the overlay from the map, recreate a line with all previous points plus the new one, generate the respective line associated with the map and add it (as overlay) on the map itself. This is quite a waste of CPU cycles.

I’ve written a set of two classes that tries to handle the Polyline growth automatically.

The project is called MapKitDynRoutes and the libraries are FFMapRoute and FFMapRoutes.

MapKitDynRoutes is shipped with a Demo project that shows how to use the library. It contains, furthermore, a small object FFLocationManager that simulates the GPS behaviour by injecting coordinates to the application using a timer and reading those from a CSV file.

MapKitDynRoutes is released under MIT license.

Posted on Jun 14, 2010

Where should I put my own code?

This is a question that you probably already asked yourself when you start developing something and you want to be supported by an SCM tool.
There are tons of solutions in the Internet and most of them are great for the most of the purposes a developer (or a team) might have.
Websites like, just to name few of those, github , repo or cz , Google code or Sourceforge are great if you are planning to develop something open-source related or just to publish some code you don’t mind others to read, copy or fork.

On the other side, there are few borderline cases that require more attention.
One of those cases happened to me when I started developing my Bachelor’s Thesis. I didn’t want an open-source, public browseable SCM because the purpose of my thesis was (still is) unknown so I didn’t know if the code should have stayed closed, private because my University had planned to acquire it once the development would have been completed.
I remembered that, during few exams and for a small indie project, I used Assembla and, as a matter of fact, I found it really great for my purposes. When I ran on their site I (sadly) discovered that there was no more a free solution so I started googling for something new.

I hit Unfuddle and I decided giving it a try. Among the plans they offer, I decided that the “free” solution was the one I was looking for. One project, 200mb storage area, infinite repositories, tickets, tracking bug and milestones was what I really need. And the code stays closed. Furthermore, the two people limit was enough for me (me and my supervisor).
My opinion? Really, really positive. I really like the way they handle projects and repositories, mail advertising and all the kind of stuff you are expected to see in a well done software development environment. Not to mention powerful commits: those really boost your producitivity up.
Something even funny happened. If you remember I’m developing an iPhone application and, about two weeks ago or so, they published Unfuddle official application on the App Store. A very convenient solution for me. In fact, I’m used to debug, analyse and test my application while I’m moving so it’s really useful to add a bug/feature report on the way while I’m testing it.

Summarizing it up: I really appreciated Unfuddle for the 4 months I’ve been using it and it will be my first choice if, in the future, I need something similar. In the mean time I advice you to take a look at it if you’re willing to start a new project or thinking about moving your existing code somewhere else.