Print("\n") printing literal rather than what Swift Book says, ..?

I posted this in Xcode -> Swift, too, but it hasn't been approved.... I don't like reading ahead in The Swift 2 Programming Language book unless I know what exactly is happening and feel comfortable. Can anyone give some insight? Thanks.


Hi, the first line of code below is from the Swift Programming book.


The issue is, print("\n") is not printing "G u t e n T a g" as described in the book, instead it is printing the literal \n.


“Use the global function indices(_:) to create a Range of all of the indexes used to access individual characters in a string.

for index in indices(greeting) {
    print("\(greeting[index]) ")
}
print("\n")
// prints "G u t e n   T a g"
”

Excerpt From: Apple Inc. “The Swift Programming Language (Swift 2 Prerelease).” iBooks. https://itun.es/us/k5SW7.l


Now... here's my code, including the index greeting so you can understand what exactly greeting is..

let greeting = "G u t e n  T a g"
greeting[greeting.startIndex]

greeting[greeting.endIndex.predecessor()]

greeting[greeting.startIndex.successor()]

let index = advance(greeting.startIndex, 0)
greeting[index]

for index in indices(greeting) {
    print("\(greeting[index])")
}
print("\n")


Help appreciated, thanks. Did I mess up?


Anthony

Your code does not match Apple's example code. Try correcting that first and see what happens...

Print("\n") printing literal rather than what Swift Book says, ..?
 
 
Q