简体   繁体   English

Swift - 没有得到println中变量名的建议

[英]Swift - not getting the suggestion for the Variable name in println

var firstLoop = 0
for i in 2..<6 {
    firstLoop += i
}
println(firstLoop)
println("\(firstLoop)")
println("\(firstLoop.description)")

Here i am printing the firstLoop variable. 这里我打印firstLoop变量。 But in the first println , when I type the word firstLoop , it is not showing any suggestions, while in next two println as I type firstLoop it is showing suggestions. 但是在第一个 println ,当我输入单词firstLoop ,它没有显示任何建议,而在接下来的两个println当我键入firstLoop它显示了建议。 Here can any one explain to me why it is not showing the suggestion in first println ? 这里有任何人可以向我解释为什么它没有在第一个println显示建议? And can I use this format to print the variable? 我可以使用这种格式打印变量吗? Is that a correct way to print the varible? 这是打印变量的正确方法吗?

That seems to be a bug. 这似乎是一个错误。 Have you tried pressing the esc-key to show code suggestions? 您是否尝试过按esc键来显示代码建议? For the second part of your question: In this case it doesn't really matter which println you use. 对于问题的第二部分:在这种情况下,使用哪种println并不重要。 The last two are essentially the same, since Swift automatically calls the description method of an object when you print it. 最后两个基本相同,因为Swift在打印时会自动调用对象的描述方法。 However, for clarity's sake I would use this 但是,为了清楚起见,我会使用它

println("firstLoop: \(firstLoop)")

to print the variable, just so you don't confuse it with another one you might print earlier or later in your code. 打印变量,只是为了让您不要将它与您可能在代码中更早或更晚打印的另一个混淆。

Yes, it is legal and correct; 是的,这是合法和正确的; there is absolutely no need to perform string interpolation merely to println something (and indeed, string interpolation merely does the same thing println itself does, namely, calls the description of a Printable). 也绝对没有必要仅仅执行字符串插值来println的东西(事实上,串插只是做同样的事情println本身,即调用description可打印的)。 You've found an Xcode code completion bug. 您找到了Xcode代码完成错误。 This has nothing to do with iOS or Swift except tangentially; 除了切线外,这与iOS或Swift无关; it's an Xcode problem. 这是一个Xcode问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM