Ant*_*ius 1 swift
假设我有一个可选的 Int 数组
var nums: [Int]?
如果不是 nil,我想将结果附加到 nums,否则直接将结果分配给 nums。
像这样的东西:
if nums == nil { nums = result } else { nums?.append(contentsOf: result) }
有没有更简单或更优雅的方法来做到这一点?
Swe*_*per 5
这是我能想到的一种方法:
nums = (nums ?? []) + result
+ 也可以用来连接数组!
+
归档时间:
5 年,10 月 前
查看次数:
131 次
最近记录: