# Let's say I've got the following typealias
public typealias DateRange = (from: NSDate?, to: NSDate?)
# And use it here
var selectedDateRange: DateRange = (nil, nil)
然後我可以使用模式匹配來獲取值並使用模式匹配將其解包嗎?模式匹配如果不爲零
# I can check vs. `nil` like so:
if case (nil, nil) = segmentControl.selectedCustomDateRange {
print("Damn, nil!")
}
# And I want something shorter than
if let from = segmentControl.selectedDateRange.from,
let to = segmentControl.selectedDateRange.to
{
model.setPeriod(from, to: to)
}
有什麼建議嗎?
啊!謝謝。我確實嘗試過變體,比如'(從:NSDate ?,到:NSDate?)',但那不起作用。 – netigger