Xcode Code Snippets

Xcode appreciation is not universal. @wtfxcode, for example, is a Twitter account relating various issues (and/or frustrations). Also, I often see threads of discussions between developers on how JetBrain’s AppCode is so much superior.

For my part, I never felt the need to switch to a new IDE. Albeit not perfect (no software/IDE is), Xcode fits my needs well.

Having said that, this post is about a bug I encountered in Xcode.

Xcode has a built-in code snippets library in the Utilities bar. (And you can add your own snippets too. See this very useful answer on stackoverflow.com). I use it mainly for Core Data fetch requests. Drag and drop, and press tab to replace parameters for your own variables.

One time I got compiling errors over this (completed) code snippet:

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"<#Entity name#>" inManagedObjectContext:<#context#>];
[fetchRequest setEntity:entity];
NSError *error = nil;
NSArray *fetchedObjects = [<#context#> executeFetchRequest:fetchRequest error:&error];             // compiling error at this line
if (fetchedObjects == nil) {
<#Error handling code#>                  // compiling error at this line
[fetchRequest release];

I stared at my code for a while, making sure that the few code I did input in there was correct, and indeed it was. I couldn’t get where the error could have come from. I tried to manually re-type the same code. The errors were gone.


checking NSError for nil

We’ve all seen this code:

NSError *error;
// do something...
if (error) { // act on error if any, but crashing instead... }

There should be nothing wrong with this code snippet. Except that there can be. I’ve countered many occasions where error was not initialized to nil by default, the if statement was evaluated to true and associated code was executed. But since there was no error, I got runtime errors, many of which were EXC_BAD_ACCESS…

Changing to:

NSError *error = nil;

made my code run fine.

In the literature I’ve read, all variables in Objective-C are initialized to nil, even if not done explicitly. This seems to be not true anymore. Does anyone have an answer to that? Please share in the comments if you do. My theory is because of the new LLVM compiler, but please prove me wrong if I am.

My playground

Project Countdown is my playground. Besides being a project I cherish a lot, a realization I am very proud of, this app is also a project for me to learn, explore, be creative! This app will also be my portfolio, but this is a side effect. It is very important, but that’s not the main reason I’m doing it.

Being creative. This is not something to toss away quickly. I never felt I had such a creative canvas! I model the product, decide which implementation is best, write the code, draw the UI… This opportunity is golden.

Last week, I’ve received Big Nerd Ranch’s new Android book. After finishing the book, I will port my app to Android and distribute it to Google Play.

Also, this app will be where I will learn more about localization and accessibility feature. This app will be where I will learn how to create a server to be able to sync my own data. And so, so much more… This is so exciting!

Once it’s done…

When I first started this project of building my first iOS app to be published in the AppStore, I did it as a goal I set myself when I turned 30, almost exactly a year ago. And that’s I introduced this blog.

I can proudly say today I achieved my goal. My app, Project Countdown, is now on the AppStore. It first got published on April 4th.

I must say the feeling of pride is great and big! I am also equally terrified! I did not test my app as much as I would’ve like it to. It might be full of bugs! I may get terrible reviews on the app store. People pay for it (it’s a .99$ app). They deserve quality software.

Like I mentioned here, another reason why I wanted to finish building my app was a contest. I finished my app in time, and I can also now say I am one of ten finalists in the contest! Game on!!! Conference on mobile app is happening tomorrow. I can’t wait to attend the conference… and for the results of the contest!

This is all so exciting!!!

Also, during the contest, I’ll be tweeting using the hashtag #gappcgodin. You can follow me on Twitter at @leblanc_f.

The big reveal!

Dear readers, I almost forgot you!

Last week was crazy. I did a last sprint that was very challenging. I finally was able to upload my binary last thursday! Current status is: “Waiting for review”. Or, in my own words: “This is so stressful and I don’t have control anymore!”. I am stressed out because there is a conference on april 10th. I am registered to attend, but I am waiting an iTunes Store link for my app to register in the conference’s contest. Without that time limit, a rejection would mean working on my app again and submit it again later on… Which is not that bad…

So I promised to tell you, finally, what my app does… Here it is!

The app is Project Countdown. At school, I have many deadlines: assignments, projects, exams… I dedicate a whole calendar to those deadlines, but I don’t care to know my final is on april 28th. Because I never know what day it is. By the time I remember that we are in March, it’s already April… So I often wake up and realize I only have a week left to study, or work on the assignment, or whatever… I want to know how many days I have left before each deadline. And that’s basically what Project Countdown does. It lets you import events from your calendar (or create fresh ones) and it gives you a prioritized list of your deadlines, letting you know how many days are left before the event, and how urgent it is. Priority is based on the number of days left, also on how many hours you think you need to put in to be on time. You can also create tasks within deadline, that later can be translated back to events.

There you go! More to come soon…

From another world

The last day or so, I was in another world. Almost literally. When I came out of the house this morning to go to school, I took a deep breath and realized how focused I am on my project (meaning: I didn’t go outside for a while!).

I consider my app ready to ship. I know it’s not perfect, and many updates will come. But that last mile I did this week was so much longer than expected! Nothing was good enough, there was always a detail to improve, a bug to fix, etc. If I didn’t impose myself a deadline for this project, I would have never shipped it.

I should have done the AppStore data part a while ago: description of the app, keywords, etc. I guess screen shots are a last-minute deal anyway. Today, I wished for a colleague. For the first time ever. That final sprint was not an easy task. But enjoying doing the work alone 99% of the way, I will not complain and continue to work alone as long as I can. Well, at least to create my first AppStore app, working alone was an absolute must.

I also want to share an amazing tutorial I came across on raywenderlich.com. Yesterday, I started to look at how to submit my app for review. When raywenderlich.com comes up in google, I always take a look. I did not regret it.

I almost forgot to mention what my app does! Later… the week is not done!


The Last Few Miles

I am very excited! My app has taken a very interesting shape. I think I will be able to submit my binary this week! I still have to localize my app, though. I will add languages over time, that’s my intention, but French and English are a bare minimum for me.

I truly hope the App Store review process won’t take too long. Coming April 17th, there is a conference here in Montreal about mobile apps. There is a contest and I want to enter it, but I have to provide a link before April 10.

I feel like it’s finally time to reveal what my app will do!

No… not yet! Follow my blog or follow me on Twitter to find out! I will reveal it this week. (You can also just come back here…)