Listing 3.1 Big or small?


In the following sample code from the 2nd book, Xcode 10 insists of message variable to be initialised when it is declared:

import Cocoa

var population: Int = 5422

var message: String

if population < 10000 {

message = “(population) is a small town!”

} else {

message = “(population) is pretty big!”



Error Message: error: Conditionals.playground:3:1: error: variables currently must have an initial value when entered at the top level of the REPL
var message: String

So, I initialise the message variable as follows before use:
var message: String = " " and the code works perfectly!