我试图做一个简单的日期格式斯威夫特,但我发现了以下错误:不能援引“stringFromDate”错误迅速
"Cannot invoke 'stringFromDate' with an argument list of type '(NSDate?!)'"
我的代码如下:
override func tableView(tableView: UITableView, cellForRowAtIndexPath
indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell",
forIndexPath: indexPath) as! UITableViewCell
// Configure the cell...
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = ("dd-MMM-yyyy")
var myUsers: AnyObject = users[indexPath.row]
let strDate = dateFormatter.stringFromDate(myUsers.createdAt)
return cell
}
}
有谁知道为什么我不能做到这一点在斯威夫特?我以前使用过这种方法,它工作正常。我已经搜索了其他答案,但我还没有找到任何合适的。
欣赏任何可用的帮助。非常感谢
你不需要首先将myUsers转换为用户对象吗?现在它是'AnyObject' –