ios - 如何进一步缩短三元运算符

标签 ios swift uitableview ternary-operator

我正在尝试清理我的代码,目前有这个三元条件。我想再次清理和重构它并使其简短。我该如何应对?

let user = AppDelegate.shared.user!.userID
let messageSender = customMessage.sender.userID
let sender = (user == messageSender)

myCell = sender ? tableView.dequeueReusableCell(withIdentifier: "firstCell", for: indexPath) : tableView.dequeueReusableCell(withIdentifier: "secondCell", for: indexPath)

最佳答案

看看这个:

let cellName = (user == messageSender) ? "firstCell" : "secondCell"
myCell = tableView.dequeueReusableCell(withIdentifier: cellName, for: indexPath)

关于ios - 如何进一步缩短三元运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52991477/

相关文章:

ios - 如何在 CorePlot 的 CPTLegend 中添加滚动条

ios - 如何在 iOS 中捕获 RNBlurModalView 关闭时的事件

ios - 更新 View Controller 之间的状态栏样式

ios - 动态 UILabel 大小 iOS 7 问题

iphone - UIView 删除自己?

ios - 当用户在 UITextView 中键入内容时,如何自动更新字符串变量?

swift - watchOS 退出代码

ios - 如何在不点击横幅或显示通知之前访问推送通知响应?

ios - 创建需要 NSCoder 的子类实例

ios - UITableView - 嵌套背景色