9

I'm just a beginner with Swift. I am trying a very basic code, but unable to print things using 'println'. This is my code,

import Cocoa
var myString:String? = nil
if myString != nil {
    println(myString)
}else {
    println("myString has nil value")
}
Shreekant
  • 297
  • 2
  • 3
  • 10

1 Answers1

24

println() does not work in xcode. Instead, print() function is used to print a statement with a newline.

If instead, you were to want to print without a newline, a terminator is used

Try this for your code:

import Cocoa
var myString:String? = nil
if myString != nil {
    print(myString)
} else {
    print("myString has nil value")
}

Example with terminator:

import Cocoa
var myString:String? = nil
if myString != nil {
    print(myString, terminator:"")
} else {
    print("myString has nil value", terminator:"")
}
Vaibhav Bajaj
  • 1,934
  • 16
  • 29