I'm trying to get the count of an optional array as a string, or nil if the array is nil.
This works:
let array: [AnyObject]? = ...
textLabel.text = (array != nil ? String((array?.count)!) : nil)
But it looks ridiculous. Is there some nicer way to write this (still as a one-liner)?
Edit: I expect the text to be "3
" not "Optional(3)
", for example.
In Objective C, this could be (array ? [@(array.count) stringValue] : nil)
.