Categories: Uncategorized

iOS Development Tips for Beginners

Making iOS apps is getting easier and easier with each new release of Xcode. However, all the new features and approaches means there are more options to choose from, outdated books and old documentation. Here are some tips to help you out.

Use ARC!

ARC is awesome, it removes a lot of the complexity of memory management. Although it’s valuable to understand memory management, ARC makes life a whole lot easier.

Prefer Blocks Where Possible

Blocks are awesome. They mean you write less code and clearer code.

There is a great tutorial on blocks here.

There are still times when delegates/protocols or NSNotifications make sense, but blocks should be your first consideration.

Beware Of Retain Cycles With Blocks

This can be nasty, rather than go into the details here check out this link.

Forget Threads, Use GCD

“A programmer had a problem, so he used threads, then he had two”

GCD has made life a lot easier, just don’t forget to switch back to the main thread before doing anything with the UI:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
    // Your code
    dispatch_async(dispatch_get_main_queue(), ^(void) {
        // Now you can interact with the UI
    });
});

There is a good explanation of GCD, including making your own queues, here.

Singletons / Shared Objects

Carrying on with GCD, dispatch_once is really useful:

    + (MyClass *)sharedClass {
static MyClass *_shared = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
    _shared = [[MyClass alloc] init];
});   
return _shared;
}

You’ll be doing this a bit, especially when you see how costly it is to create things like NSDateFormatter many times.

Keep Your Project Organised

I’ve done a bit of Ruby on Rails development and quite like the way they organise a project, so I do something similar in Xcode:

However you do it, try and keep it in some sort of order, it will get out of hand pretty quickly.

Embrace Open Source

There are so many amazing libraries and components available for iOS development. Github is full of great source code that you can just drop into your project, you can also use sites like Cocoa Controls to find components.

Some libraries I use in almost every project include:

If you Google for a component you need chances are there is one out there to at least get you started.

Dependency Management

With all these great open source components you’ll need a way to manage them. CocoaPods has done an amazing job at making something similar to Ruby’s gems. Otherwise you can just use git submodules.

Custom Fonts

In early iOS versions (pre 3.2) this was a nightmare, so everyone just used Helvetica. Luckily now it’s simple!

Here is a quick guide. If you get stuck with the name of the font open up Font Book and look for the PostScript name.

Localize From The Start

Localization is pretty easy to do in Xcode, especially if you avoid xibs. But add localization support from the start of your project, it’s a long painful experience to extract them later.

Here is a great guide to localizing an iPhone app.

Track Crashes

Crash logs are a pain, a real pain. Use a service that captures and symbolicates them for you. Two great services are HockeyApp and TestFlight

[divider]

This post has been reproduced from Stuart Hall’s blog. Read more tips and resources from him on his blog.

Team TechPanda

Recent Posts

Indic language adoption spurs Internet users in India to cross 900 M

The internet user base in India is set to surpass 900 million by 2025, driven…

1 day ago

Google signs one of the largest industrial Biochar CDR offtake agreements in India

Varaha, an Indian company developing carbon removal projects in Asia, has sold 100,000 carbon dioxide…

1 day ago

Google’s Willow: The quantum leap we’ve been waiting for

Ever wondered what happens when quantum computing takes a giant leap forward? Google’s latest quantum…

2 days ago

The wise thing to do is work in tandem with AI regulation by keeping the human element relevant

Does AI need to be reined in? Will putting regulations on AI curb the progress…

4 days ago

Tech Panda’s 40 under 40 tech innovators of 2024 

By definition of the Merriam-Webster dictionary, ‘technology’ means ‘the practical application of knowledge especially in…

4 days ago

Nvidia, AI, and Bitcoin Take Center Stage in 2024 Tech Trends

This is the second-last edition of this year's "Tech, What the Heck!?" newsletter. To commemorate…

1 month ago