NSLog
在 Swift 中仍然存在,并且提供了一些 println
不可用的额外功能,例如时间戳、模块和线程。
然而,我不确定如何记录一个可选项,例如一个可选的 Int
。
记录一个已展开的可选项可以正常工作,例如:
if let i = myIndex
{
NSLog("%@ i %d", __FUNCTION__, i)
}
尝试记录
myIndex
,我希望它是一个对象,因此使用格式说明符%@
;NSLog("%@ myIndex %@", __FUNCTION__, myIndex)
出现构建错误:
Value of optional type 'Int?' not unwrapped; did you mean to use '!' or '?'?
我该如何使用
NSLog
- 而不是println - 将我的可选整数打印到控制台?
let i: Int? = 5
NSLog("%@", toString(i))
- Kirsteins