Control flow
Objective-C has many of the same control flow paradigms as Swift. We will go through each of them quickly, but before we do, let's look at the Objective-C equivalent of println
:
var name = "Sarah" println("Hello \(name)") NSString *name = @"Sarah"; NSLog(@"Hello %@", name);
Instead of println
, we are using a function called NSLog
. Objective-C does not have string interpolation, so NSLog
is a somewhat more complex solution than println
. The first argument to NSLog
is a string that describes the format to be printed out. This includes a placeholder for each piece of information we want to log that indicates the type it should expect. Every placeholder starts with a percent symbol. In this case, we are using an @
symbol to indicate that we will substitute in a string. Every argument after the initial format will be substituted for placeholders in the same order that they are passed in. Here, this means that it will end up logging Hello Sarah
just like the Swift code.
Now, we are...