Reputation: 363
How can I create a single element tuple in Swift?
var a = 10
var tup = (a,)
print(tup)
But this code gives me a build-time error.
also,
I cannot write var tup = (a)
, as this just creates an integer variable.
Upvotes: 1
Views: 1008
Reputation: 4383
What about this solution?
typealias SingleTuple = (Int, Void)
var a = 10
var tup: SingleTuple = (a, ())
print(tup)
Upvotes: 2