An Overview of Apple’s Swift Programming Language

Screen-Shot-2014-06-03-at-6.47.25-am-730x450

The jaws of iOS developers everywhere dropped with the announcement at WWDC yesterday that Apple was introducing a new programming language to eventually replace Objective-C, called Swift. The surprise wasn’t that they did it (everyone knew it had to be done), but that it happened so soon. Apple has so much institutional knowledge of Objective-C that to replace it is truly a massive sea change. The problem with Objective-C, being a 25-year old mashup of C and Smalltalk, is that is was never quite fully-baked. And it was not suited for high-performance code, causing developers to revert to C or C++ in many cases. Here are my initial thoughts and observations on how Swift compares to Objective-C and other modern languages. There’s a LOT to cover, so I just picked out the interesting bits:
Continue reading

How to Accept Multiple Enum Values in a Property or Method

enum

Every iOS developer has probably come across a property or method in an API that accepts multiple enum values at once, separated by a vertical pipe. How does that work, and how can we do the same?

Continue reading

How to Swap Two Variables Without Using a Temp Variable

swap

With all the high-level languages in widespread use today, it is often easy to forget that at the end of the day, everything boils down to binary: ones and zeroes. This is shielded from us via multiple layers of abstraction. There is nothing wrong with using these abstractions; they have made great modern-day development possible. At the same time, they conceal some of the more intriguing quirks that are inherent in the binary system. This includes bitwise operations, and specifically an operation called a bitwise swap. This is a very efficient operation that can exchange the values of two variables of the same type without using an intermediary variable, and looks like this in C:

Continue reading

The Great Pointer Syntax Debate

Asterisk

In Objective-C and other C-based languages, pointers are declared using the asterisk character. So, to declare a pointer to a UIView object called foo, in most examples and documentation you will see:

Continue reading

Double Pointers in Objective-C

Pointers

Ah, pointers. Nothing strikes more fear into the heart of novice C programmers, or developers who aren’t used to them. Add to that the notion of double pointers (**) and address-of operators (&) and you are pretty much guaranteed to scare them away. But they are really not that hard, as long as you understand 3 things:

Continue reading

Why Static Code is Bad

static

Most object-oriented developers are familiar with static methods and classes. They are present in most programming languages including C# and Objective-C (where they are known as class methods). Here are some common cases in which they are used: Continue reading