Aaron Brager
Dec 16, 2015 · 6 min read

Learning to write iOS apps and already know another programming language? Here are a few tips.

If you’re a beginner, “Should I learn Swift or Objective-C for iOS development?” may be more interesting.

1. Start by Exploring Xcode

Unlike many other development environments, an iOS application development environment is easy to configure. Here are the steps:

  1. Download and install Xcode from the App Store
  2. Create an Apple Developer Account (free)

There’s ample command-line access if you want automation or need advanced workflows, but most work can be done within Xcode.

Xcode combines a powerful code text editor with graphical interfaces to a compiler, linter, debugger, user interface builder, documentation, and more. If you’re coming from a world where those are all separate, you’re in for a treat.

2. Decide Between Swift and Objective-C

One of the first choices you’ll make is which language to learn: Swift or Objective-C. Swift is newer and more modern, but it’s conceptually different from many web programming languages. Unlike Ruby and JavaScript, for example, Swift requires nil-checking and has strict type safety, including for collections. Objective-C is a freer language, more similar to Ruby and JavaScript, but with some weird syntax, verbose language, and less intuitive conventions.

Objective-C has a few advantages:

  1. Its syntax and usage is stable: tutorials and code samples from years ago work with only minor modifications.
  2. It’s very popular: most iOS app code bases are primarily written in Objective-C.
  3. Most iOS Developer job openings require Objective-C knowledge.

Swift has some strong advantages over Objective-C, though:

  1. A REPL, with an accompanying graphical interface called a “playground”. (A REPL is a console interface to a programming language, like irb, Pry, or node.)
  2. Swift has a great library from Apple of manuals, tutorials, and videos.
  3. It’s open-source, so you can see how it works and change it.

This video explores the differences a bit more. Both languages are powerful and full-featured, and both have full use of the iOS SDK.

If you’re not sure, I recommend starting with Objective-C, since that’s where the bulk of the job openings are at the moment. But you can’t go wrong either way.

3. Learn the Debugging Tools

Xcode’s debugging tools are among the industry’s best. Learn to use them for fast and efficient debugging and performance improvements. Some quick tips:

  • Set a breakpoint by clicking on the line number. When the line is reached, execution will pause.
  • Hover your mouse over a variable to see into its contents.
  • Click a variable and press space bar to see a visual representation of its data (for example, if it’s an image or a color).
  • Use LLDB to debug your app while execution is paused.
  • Use Static Analysis to find logical flaws in your code.

Here are some resources to get started:

4. Learn to Decipher Square Brackets

This method syntax is widely considered to be ugly:

[self.view insertSubview:button atIndex:2];

Confused? Don’t be:

  • The first statement is the object that the method is called on (the receiver).
  • The remaining statements are the method name interwoven with arguments:

In Swift, the same method call looks a lot more like JavaScript or Ruby:

view.insertSubview(button, atIndex: 2)

Learning to quickly interpret Objective-C square bracket notation is critical to your success as an iOS developer. Even if you’re working on apps in Swift, you’ll likely read sample code in Objective-C.

5. Don’t Be Intimidated by Objective-C’s Verbosity

Say you have a string like ‘2,4,5’ that you’d like to convert to an array. In a language like Ruby you’d use split:

'2,4,5'.split(',')

Objective-C has a similar feature, but its syntax is much more verbose:

[@"2,4,5" componentsSeparatedByString:@","];

Want to turn that array back into a string? Objective-C doesn’t have join; it has:

[@[@"2", @"4", @"5"] componentsJoinedByString:@","];

Objective-C naming conventions are more verbose than those in many other languages. It’s tempting to think that these methods are more complicated — or harder — because they’re longer, but they’re not.

Just like with the previous tip, even if you plan to work solely in Swift, it’s important to understand Objective-C’s style so you can read and interpret it correctly.

6. Understand Object vs. Value Semantics

In Ruby, everything’s an object. The same is (mostly) true of JavaScript. But in Objective-C there’s an important separation between primitive (value) types and objects. To bridge the gap, wrap primitive types in an NSValue or NSNumber object. For example:

// ERROR: implicit conversion is disallowed
[mutableArray addObject:7];
// Works great
[mutableArray addObject:[NSNumber numberWithInt:7]];
// You can also use this shorthand
[mutableArray addObject:@(7)];

In Objective-C, object semantics are required. In Swift, you can use objects or values for most things, but values are strongly preferred. This is another strong difference between Swift and most web programming languages.

If you’re working in Swift, read Value and Reference Types, and watch the Building Better Apps with Value Types in Swift video.

7. Understand Automatic Reference Counting

Objective-C and Swift apps (mostly) manage memory using Automatic Reference Counting (ARC). This contrasts with languages like Ruby, JavaScript, and Java, which use Garbage Collection.

In ARC, objects stay in memory if there is at least one strong reference to it. For example:

self.label.text = @"Hello World";

In this example, the string object (@“Hello World”) will stay in memory because it has one strong reference (from label). Now consider this:

self.label = nil;

Two things will happen:

  • The label object will be deallocated because self is no longer referencing it
  • The string object will be deallocated because label no longer exists, and therefore is no longer referencing the string

Be careful not to create a strong reference cycle (also called a retain cycle). This is an error caused by a circular graph of objects pointing to each other. It wastes memory and can cause other negative side effects. Here’s an example:

Because all of these objects have at least one strong reference, none of them will ever be deallocated. To resolve this, switch one of the references from strong to weak:

With a weak reference, if the CarDealership instance gets deallocated, all of its cars will get deallocated as we’d expect.

Thanks for reading these tips. I hope you found a few of them helpful. Follow me on Twitter if you’d like to get in touch.

If you’re interested in learning more by pair programming with a senior iOS developer, check out Bloc’s iOS for Engineers course.

iOS App Development

Stories and technical tips about building apps for iOS, Apple Watch, and iPad/iPhone

Aaron Brager

Written by

I have a secret plan to fight inflation. Also, I code iOS apps, try to understand ideas I disagree with, and sometimes play chess.

iOS App Development

Stories and technical tips about building apps for iOS, Apple Watch, and iPad/iPhone

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade