Header Image - Riee Design

A Guide To Common Swift Questions

Ten of the most important aspects of Swift

Swift is the latest programming language released by Apple and meant to replace Objective-C. For many people transitioning to Swift from Objective-C or just learning Swift with a Java background, I’ve written a quick summary over the most important aspects of the Swift language. Here are ten of the most important aspects of the new language that you’ve probably have questions about when learning Swift – I know that I had!

Question 1: What is the question mark ? in Swift?
Answer: The question mark ? when used in declaration of a property, tells the compiler that this property is optional. The property may hold a value or not, in the latter case it’s possible to avoid runtime errors when accessing that property by using ?.  This useful in optional chaining (see below) and a variant of this example is in conditional clauses.
var optionalName : String? = “John"
if optionalName != nil {
    print(“Your name is \(optionalName!)”)