我想知道如何声明IndexPath类型的变量。如果有人可以向我展示如何使用内联条件,这也将非常有帮助。
var indexPath = 0
if PlaylistController.shared.playlists.count == 1 {
indexPath = IndexPath(item: sender.tag +1, section: 0)
}
else {
indexPath = IndexPath(item: sender.tag -1, section: 0)
}
只需更改行:
var indexPath = 0
至:
let indexPath: IndexPath
或将整个内容替换为:
let indexPath = IndexPath(item: sender.tag + (PlaylistController.shared.playlists.count == 1 ? 1 : -1), section: 0)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句