在swift 3中使用未解析标识符‘println’[duplicate]

时间:2022-12-01 06:30:59

This question already has an answer here:

这个问题已经有了答案:

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:"")
}