【发布时间】:2018-08-13 00:16:39
【问题描述】:
好吧,这很难。我正在构建一个社交媒体应用程序,它的提要有一个 Uitableview,它存储在帖子包含的 firebase 实时数据库中
作者 文字:“嗨” 时间戳:“1532194221795”
我的目标是以更吸引人的方式在我的单元格中显示此时间戳,例如(15 分钟前、2 小时前、5 天前、2 个月前)根据单元格的发布时间。
我的 NewPostViewController 中有这个
"timestamp": [".sv":"timestamp"]
像这样let timestamp = dict["timestamp"] as? Double {在我的提要中保存为双精度
它由我的 PostTableViewCell subtitleLabel.text = "\(post.timestamp)" 显示在桌子上
我也收集过这样的信息
`func timeSinceNowString() -> 字符串 { 让 calendar = Calendar.current
let components = calendar.dateComponents([.day, .hour, .minute, .second], from: self, to: Date())
if components.day! >= 365 {
return "\(components.day! / 365) years ago"
}
if components.day! >= 7 {
return "\(components.day! / 7) weeks ago"
}
if components.day! > 0 {
return "\(components.day!) days ago"
}
else if components.hour! > 0 {
return "\(components.hour!) hours ago"
}
else if components.minute! > 0 {
return "\(components.minute!) minutes ago"
}
return "Now"
}
and this tooDate(timeIntervalSince1970: createdAt / 1000)`
它给我的错误,比如表达式类型在没有更多上下文的情况下是模棱两可的”对于第一部分和“使用未解析的标识符'createdAt'”对于日期第二部分。有谁知道如何在没有这些错误的情况下进行设置?我永远爱你,感谢阅读。
【问题讨论】:
标签: ios xcode uitableview firebase timestamp