Im curious to know the reasoning behind why implicit-wrapped optionals
aren't allowed when creating tuples. Below is an example with type aliases
and anonymous tuples.

ex.

typealias Name = (first: String!, middle: String?, last: String!)

typealias Name = (first: String!, middle: String?, last: String!)!

var name : (first: String!, middle: String?, last: String!)
var name : (first: String!, middle: String?, last: String!)!

error from all 4 examples above:
Implicitly unwrapped optionals are only allowed at top level and as
function results


I also noticed that I can modify tuples using functions ONLY if I use
*inout*.

func name(Person : inout (first: String?, middle: String?, last: String?)) {

    Person.first = "John"

    Person.last = "Doe"

}


OR


func name(Person : inout Name) {

    Person.first = "John"

    Person.last = "Doe"

}

This is because tuples are passed into functions as 'let' constants. Why
not add the ability to modify a copy of the tuple inside the function ?


-- 
Best Regards,

Muhammad T. Vali
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to