When assigning a tuple, say, of Intmembers, to a tuple of a (heterogeneous) type of protocol, which corresponds Int, apparently, it is allowed to perform this assignment only through an explicit member after the assignment element.
protocol MyType {}
extension Int: MyType {}
let intPair = (1, 2)
var myTypePair : (MyType, MyType)
myTypePair = (intPair.0, intPair.1)
let intPairToMyTypePair : ((Int, Int)) -> (MyType, MyType) = { ($0.0, $0.1) }
myTypePair = intPairToMyTypePair(intPair)
myTypePair = intPair
myTypePair = (intPair as! (MyType, MyType))
if let _ = intPair as? (MyType, MyType) { }
The peculiarity is that for cases of casting above, the Swift compiler warns that
warning: forced / conditional drop from '(Int, Int)'to '(MyType, MyType)' always performed
This clearly does not mean:
error: unable to express tuple conversion '(Int, Int)'before'(MyType, MyType)'
: , , ? , , ?
( )
, : , "bar", , 'is' case is always true:
let intPair = (1, 2)
switch intPair {
case is (MyType, MyType): print("foo") /* warning: 'is' test is always true */
case _ : print("bar")
}
// "bar"
, , , , Array.
let intArr = [Int](1...5)
var myTypeArr : [MyType]
myTypeArr = intArr
/* error: cannot assign value of type '[Int]' to type '[MyType]' */
if let _ = intArr as? [MyType] { }
/* error: 'MyType' is not a subtype of 'Int' */