【发布时间】:2015-04-01 09:41:14
【问题描述】:
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 - not println - 来控制我的 Optional Int?
【问题讨论】: