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.

Advertisement

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…)

 

Let’s get technical!

I haven’t talked about what my app will be yet. And I have been very shy on detailing my progress. Even though it’s the main purpose of this blog, it often felt worthless… I don’t write as much as I would want to, so when I do, I talk about things that seem more useful.

Today I came accross an issue. Actually I have been having this issue for a few days, but until today, I could avoid it. So I did.

I tried to debug as much as I could, checking the debug navigator, outputting everything that seemed relevant to the console, trying to analyse the call stack so I could figure out what the app was trying to accomplish… Because of course, the error I got was EXC_BAD_ACCESS code = 1. Which means: you have a memory error, now find it.

Where do I go to? Being an indie developer, I can’t turn to a collegue. I don’t do code review. An old collegue of mine use to help me out via screen sharing, but he’s charging me… I finally turned to my best friend stackoverflow.com. I asked my question, trying to be as detailed as possible. But I am always shy to ask a question there! I am always afraid I will look stupid, too new to do anything useful, or just helpless! I am always glad someone asked the same question I have before me so I can just read the answer and be happy!

I create custom views on one of my UIViewController. These views have two labels that I set with specific values; one int and one string. In the first iteration of the UIView class, the int (called number) was an actual int. So the property was declared:

@property (assign, nonatomic) int number;

Later on, I changed number to be an NSNumber, but didn’t change the property declaration. It caused a memory error when the view was accessing _number to set the label properly. Changing the property to:

@property (strong, nonatomic) NSNumber *number;

fixed my issue.

Back to coding!

Doubting myself

Continuing without doubting myself is hard these days. I don’t doubt myself on a technical or programming point of view. I doubt myself because of money, or lack thereof.

Lastly, I have been spending quite some time on my app. The efforts are not wasted! I now have a very, very basic functionality in my app. Too basic to talk about, or publish, but enough to distinguish it as an app, and not some kind of primitive form.

Like I mention here, I log my hours. And one of the impact is I see all the hours I am putting into this project that I won’t charge to anyone. I like billing my hours.

At the same time, when I peek into job offers, I often see: “published at least n app(s) to the AppStore”. (Example here or here. Note that these examples require more experience that I have anyway, but I you get the point! I also see this requirement for low experience jobs). These efforts are not wasted. By any measure.

So on one side, I am currently working on a project that won’t pay my next rent, nor the one after that. But on the other side, this will be a key asset when looking for a job.

Another reason to keep me coding this non-profitable project is a conference that will happen here in Montréal (Québec) next April. If my app is ready, it will be presented… More on that conference in upcoming posts…

Counting time

From the -almost- beginning of the project, I decided I would keep a record for hours I work on the project. I thought (and I still do think) that it would give me a better idea of hours it takes to create a simple app.

More precisely, I would be better at estimating the time it takes to create one feature, fix one bug.

So each time I am sitting down to work on my app, I am counting time and log the activity I am doing. I don’t know if there’s anything else relevant to log?

I think there is a lot of benefits from doing that. Plus, I actually have numbers in my face telling me I didn’t spend that much time on the project! So let’s get going!