Swift – Initialize a Tuple

To initialize a Tuple with values in Swift, assign the comma separated values enclosed in parenthesis to a tuple variable.

The syntax to initialize a tuple is

(value1, value2, ..., valueN)

Values can be of different datatypes.

Examples

In the following program, we initialize a Tuple x with values, and print it to console.

main.swift

var x = ("Hello", 35, true)
print(x)

Output

("Hello", 35, true)
Program ended with exit code: 0

Conclusion

In this Swift Tutorial, we have learned how to initialize a Tuple with values in Swift programming.