Kushal Mukherjee
Kushal Mukherjee

Reputation: 363

Single element tuple in swift?

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

Answers (1)

Vlad Khambir
Vlad Khambir

Reputation: 4383

What about this solution?

 typealias SingleTuple = (Int, Void)

 var a = 10
 var tup: SingleTuple = (a, ())
 print(tup)

Upvotes: 2

Related Questions