This question already has an answer here:
这个问题已经有了答案:
- How do you do println() in swift 2 [duplicate] 4 answers
- 您如何在swift 2[重复]4个答案中执行println() ?
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,
我对斯威夫特只是个初学者。我正在尝试一种非常基本的代码,但是无法使用“println”打印东西。这是我的代码,
import Cocoa
var myString:String? = nil
if myString != nil {
println(myString)
}else {
println("myString has nil value")
}
1 个解决方案
#1
18
println()
does not work in xcode. Instead, print()
function is used to print a statement with a newline.
println()在xcode中不工作。相反,print()函数用于打印带有换行符的语句。
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:"")
}
#1
18
println()
does not work in xcode. Instead, print()
function is used to print a statement with a newline.
println()在xcode中不工作。相反,print()函数用于打印带有换行符的语句。
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:"")
}