Error[8]: Undefined offset: 6, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述当将Int成员的元组分配给Int符合的(异构)协议类型的元组时,似乎只允许通过显式的逐个成员赋值来执行此赋值. protocol MyType {}extension Int: MyType {}let intPair = (1, 2)var myTypePair : (MyType, MyType)// OKmyTypePair = (intPair.0, intPair.1) 当将Int成员的元组分配给Int符合的(异构)协议类型的元组时,似乎只允许通过显式的逐个成员赋值来执行此赋值.

protocol MyType {}extension Int: MyType {}let intPair = (1,2)var myTypePair : (MyType,MyType)// OKmyTypePair = (intPair.0,intPair.1)// OKlet intPairToMyTypePair : ((Int,Int)) -> (MyType,MyType) = { ('(Int,Int)'.0,'(MyType,MyType)'.1) }myTypePair = intPairToMyTypePair(intPair)// For all below: // "Error: cannot express tuple conversion '(Int,Int)' to '(MyType,MyType)'"myTypePair = intPairmyTypePair = (intPair as! (MyType,MyType))    /* warning: forced cast from '(Int,MyType)'                 always succeeds <-- well,not really */if let _ = intPair as? (MyType,MyType) { }    /* warning: conditional cast from '(Int,MyType)'                 always succeeds */

特点是,对于上面的转换情况,Swift编译器警告说

warning: forced/conditional cast from '(Int,MyType)'
to

let intPair = (1,2)switch intPair {case is (MyType,MyType): print("foo") /* warning: 'is' test is always true */case _ : print("bar")}    // "bar"
always succeeds

它显然没有:

error: cannot express tuple conversion

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' */

问题:这里的问题是,是否按预期不允许直接转让?如果是这样,怎么了警告信息,铸件将永远成功?

(编辑补充)

为了进一步澄清我在这里要求的特殊行为:我想知道为什么即使Swift警告我们“是”的情况总是如此,以下片段也会打印出“bar”:

[+++]

数组的类似情况很简单,有解释错误,但我不知道这是否是一个有效的比较,因为元组更多是匿名结构而不是某些表兄.

[+++]解决方法 在这种情况下警告是正确的,因为intPair是(Int,Int)符合(MyType,MyType).所以演员阵容将永远成功.由于强类型检查,编译器知道此特定实例将始终成功.

为什么myTypePair = intPair错误是因为myTypePair比intPair更通用,更具体.因此类型不匹配,因此无法分配.

总结

以上是内存溢出为你收集整理的swift – 分配关联类型的元组,为什么只允许通过显式的逐个成员分配? (错误:无法表达元组转换)全部内容,希望文章能够帮你解决swift – 分配关联类型的元组,为什么只允许通过显式的逐个成员分配? (错误:无法表达元组转换)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 7, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述当将Int成员的元组分配给Int符合的(异构)协议类型的元组时,似乎只允许通过显式的逐个成员赋值来执行此赋值. protocol MyType {}extension Int: MyType {}let intPair = (1, 2)var myTypePair : (MyType, MyType)// OKmyTypePair = (intPair.0, intPair.1) 当将Int成员的元组分配给Int符合的(异构)协议类型的元组时,似乎只允许通过显式的逐个成员赋值来执行此赋值.

protocol MyType {}extension Int: MyType {}let intPair = (1,2)var myTypePair : (MyType,MyType)// OKmyTypePair = (intPair.0,intPair.1)// OKlet intPairToMyTypePair : ((Int,Int)) -> (MyType,MyType) = { ('(Int,Int)'.0,'(MyType,MyType)'.1) }myTypePair = intPairToMyTypePair(intPair)// For all below: // "Error: cannot express tuple conversion '(Int,Int)' to '(MyType,MyType)'"myTypePair = intPairmyTypePair = (intPair as! (MyType,MyType))    /* warning: forced cast from '(Int,MyType)'                 always succeeds <-- well,not really */if let _ = intPair as? (MyType,MyType) { }    /* warning: conditional cast from '(Int,MyType)'                 always succeeds */

特点是,对于上面的转换情况,Swift编译器警告说

warning: forced/conditional cast from '(Int,MyType)'
to

let intPair = (1,2)switch intPair {case is (MyType,MyType): print("foo") /* warning: 'is' test is always true */case _ : print("bar")}    // "bar"
always succeeds

它显然没有:

error: cannot express tuple conversion

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' */

问题:这里的问题是,是否按预期不允许直接转让?如果是这样,怎么了警告信息,铸件将永远成功?

(编辑补充)

为了进一步澄清我在这里要求的特殊行为:我想知道为什么即使Swift警告我们“是”的情况总是如此,以下片段也会打印出“bar”:

数组的类似情况很简单,有解释错误,但我不知道这是否是一个有效的比较,因为元组更多是匿名结构而不是某些表兄.

[+++]解决方法 在这种情况下警告是正确的,因为intPair是(Int,Int)符合(MyType,MyType).所以演员阵容将永远成功.由于强类型检查,编译器知道此特定实例将始终成功.

为什么myTypePair = intPair错误是因为myTypePair比intPair更通用,更具体.因此类型不匹配,因此无法分配.

总结

以上是内存溢出为你收集整理的swift – 分配关联类型的元组,为什么只允许通过显式的逐个成员分配? (错误:无法表达元组转换)全部内容,希望文章能够帮你解决swift – 分配关联类型的元组,为什么只允许通过显式的逐个成员分配? (错误:无法表达元组转换)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
swift – 分配关联类型的元组,为什么只允许通过显式的逐个成员分配? (错误:无法表达元组转换)_app_内存溢出

swift – 分配关联类型的元组,为什么只允许通过显式的逐个成员分配? (错误:无法表达元组转换)

swift – 分配关联类型的元组,为什么只允许通过显式的逐个成员分配? (错误:无法表达元组转换),第1张

概述当将Int成员的元组分配给Int符合的(异构)协议类型的元组时,似乎只允许通过显式的逐个成员赋值来执行此赋值. protocol MyType {}extension Int: MyType {}let intPair = (1, 2)var myTypePair : (MyType, MyType)// OKmyTypePair = (intPair.0, intPair.1) 当将Int成员的元组分配给Int符合的(异构)协议类型的元组时,似乎只允许通过显式的逐个成员赋值来执行此赋值.

protocol MyType {}extension Int: MyType {}let intPair = (1,2)var myTypePair : (MyType,MyType)// OKmyTypePair = (intPair.0,intPair.1)// OKlet intPairToMyTypePair : ((Int,Int)) -> (MyType,MyType) = { ('(Int,Int)'.0,'(MyType,MyType)'.1) }myTypePair = intPairToMyTypePair(intPair)// For all below: // "Error: cannot express tuple conversion '(Int,Int)' to '(MyType,MyType)'"myTypePair = intPairmyTypePair = (intPair as! (MyType,MyType))    /* warning: forced cast from '(Int,MyType)'                 always succeeds <-- well,not really */if let _ = intPair as? (MyType,MyType) { }    /* warning: conditional cast from '(Int,MyType)'                 always succeeds */

特点是,对于上面的转换情况,Swift编译器警告说

warning: forced/conditional cast from '(Int,MyType)'
to

let intPair = (1,2)switch intPair {case is (MyType,MyType): print("foo") /* warning: 'is' test is always true */case _ : print("bar")}    // "bar"
always succeeds

它显然没有:

error: cannot express tuple conversion

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' */

问题:这里的问题是,是否按预期不允许直接转让?如果是这样,怎么了警告信息,铸件将永远成功?

(编辑补充)

为了进一步澄清我在这里要求的特殊行为:我想知道为什么即使Swift警告我们“是”的情况总是如此,以下片段也会打印出“bar”:

数组的类似情况很简单,有解释错误,但我不知道这是否是一个有效的比较,因为元组更多是匿名结构而不是某些表兄.

解决方法 在这种情况下警告是正确的,因为intPair是(Int,Int)符合(MyType,MyType).所以演员阵容将永远成功.由于强类型检查,编译器知道此特定实例将始终成功.

为什么myTypePair = intPair错误是因为myTypePair比intPair更通用,更具体.因此类型不匹配,因此无法分配.

总结

以上是内存溢出为你收集整理的swift – 分配关联类型的元组,为什么只允许通过显式的逐个成员分配? (错误:无法表达元组转换)全部内容,希望文章能够帮你解决swift – 分配关联类型的元组,为什么只允许通过显式的逐个成员分配? (错误:无法表达元组转换)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/999895.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存