Error[8]: Undefined offset: 5, 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(

概述我有两个协议Valid和Resetable以及一个类型为[Valid]的inputViews数组.一切正常.所以现在我有了我的Resetable协议: protocol Resetable: class { func reset()} 现在,inputViews中的所有内容也符合Resetable协议,所以我想要做的基本上是循环并在每个成员上调用reset().如果我这样做,那么它将起作 我有两个协议ValID和resetable以及一个类型为[ValID]的inputVIEws数组.一切正常.所以现在我有了我的resetable协议:

protocol resetable: class {    func reset()}

现在,inputVIEws中的所有内容也符合resetable协议,所以我想要做的基本上是循环并在每个成员上调用reset().如果我这样做,那么它将起作用:

for input in inputVIEws {        (input as! resetable).reset()    }

但是我用以下方法扩展了Array:

extension Array where Element:resetable {    func resetAll() {        forEach({ 
let resetableVIEws = inputVIEws.map({ 
protocol resettable {    func reset() -> resettable}struct resettableArray {    var array: [resettable]    init(_ array:[resettable]) { self.array = array }    func resetAll() -> [resettable] {        return array.map( { [+++].reset() } )    }}class dummy: resettable {    func reset() -> resettable {        print("reset one element")        return self    }}let resettableDummy = resettableArray([dummy(),dummy()])resettableDummy.resetAll()
as! resetable }) resetableVIEws.resetAll()
.reset() }) }}

所以我真正希望能够完成的是downcast inputVIEws并调用resetAll().

我试过了:

[+++]

但它表示不支持使用resetable作为符合resetable的具体类型

如何通过使用resetAll()实现此目的?

解决方法 我希望我已经理解了问题/规格.从Rob NAPIer自由采取,如何:

[+++] 总结

以上是内存溢出为你收集整理的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: 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(

概述我有两个协议Valid和Resetable以及一个类型为[Valid]的inputViews数组.一切正常.所以现在我有了我的Resetable协议: protocol Resetable: class { func reset()} 现在,inputViews中的所有内容也符合Resetable协议,所以我想要做的基本上是循环并在每个成员上调用reset().如果我这样做,那么它将起作 我有两个协议ValID和resetable以及一个类型为[ValID]的inputVIEws数组.一切正常.所以现在我有了我的resetable协议:

protocol resetable: class {    func reset()}

现在,inputVIEws中的所有内容也符合resetable协议,所以我想要做的基本上是循环并在每个成员上调用reset().如果我这样做,那么它将起作用:

for input in inputVIEws {        (input as! resetable).reset()    }

但是我用以下方法扩展了Array:

extension Array where Element:resetable {    func resetAll() {        forEach({ 
let resetableVIEws = inputVIEws.map({ 
protocol resettable {    func reset() -> resettable}struct resettableArray {    var array: [resettable]    init(_ array:[resettable]) { self.array = array }    func resetAll() -> [resettable] {        return array.map( { .reset() } )    }}class dummy: resettable {    func reset() -> resettable {        print("reset one element")        return self    }}let resettableDummy = resettableArray([dummy(),dummy()])resettableDummy.resetAll()
as! resetable }) resetableVIEws.resetAll()
.reset() }) }}

所以我真正希望能够完成的是downcast inputVIEws并调用resetAll().

我试过了:

[+++]

但它表示不支持使用resetable作为符合resetable的具体类型

如何通过使用resetAll()实现此目的?

解决方法 我希望我已经理解了问题/规格.从Rob NAPIer自由采取,如何:

[+++] 总结

以上是内存溢出为你收集整理的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(

概述我有两个协议Valid和Resetable以及一个类型为[Valid]的inputViews数组.一切正常.所以现在我有了我的Resetable协议: protocol Resetable: class { func reset()} 现在,inputViews中的所有内容也符合Resetable协议,所以我想要做的基本上是循环并在每个成员上调用reset().如果我这样做,那么它将起作 我有两个协议ValID和resetable以及一个类型为[ValID]的inputVIEws数组.一切正常.所以现在我有了我的resetable协议:

protocol resetable: class {    func reset()}

现在,inputVIEws中的所有内容也符合resetable协议,所以我想要做的基本上是循环并在每个成员上调用reset().如果我这样做,那么它将起作用:

for input in inputVIEws {        (input as! resetable).reset()    }

但是我用以下方法扩展了Array:

extension Array where Element:resetable {    func resetAll() {        forEach({ 
let resetableVIEws = inputVIEws.map({ 
protocol resettable {    func reset() -> resettable}struct resettableArray {    var array: [resettable]    init(_ array:[resettable]) { self.array = array }    func resetAll() -> [resettable] {        return array.map( { .reset() } )    }}class dummy: resettable {    func reset() -> resettable {        print("reset one element")        return self    }}let resettableDummy = resettableArray([dummy(),dummy()])resettableDummy.resetAll()
as! resetable }) resetableVIEws.resetAll()
.reset() }) }}

所以我真正希望能够完成的是downcast inputVIEws并调用resetAll().

我试过了:

但它表示不支持使用resetable作为符合resetable的具体类型

如何通过使用resetAll()实现此目的?

解决方法 我希望我已经理解了问题/规格.从Rob NAPIer自由采取,如何:

[+++] 总结

以上是内存溢出为你收集整理的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张

概述我有两个协议Valid和Resetable以及一个类型为[Valid]的inputViews数组.一切正常.所以现在我有了我的Resetable协议: protocol Resetable: class { func reset()} 现在,inputViews中的所有内容也符合Resetable协议,所以我想要做的基本上是循环并在每个成员上调用reset().如果我这样做,那么它将起作 我有两个协议ValID和resetable以及一个类型为[ValID]的inputVIEws数组.一切正常.所以现在我有了我的resetable协议:

protocol resetable: class {    func reset()}

现在,inputVIEws中的所有内容也符合resetable协议,所以我想要做的基本上是循环并在每个成员上调用reset().如果我这样做,那么它将起作用:

for input in inputVIEws {        (input as! resetable).reset()    }

但是我用以下方法扩展了Array:

extension Array where Element:resetable {    func resetAll() {        forEach({ 
let resetableVIEws = inputVIEws.map({ 
protocol resettable {    func reset() -> resettable}struct resettableArray {    var array: [resettable]    init(_ array:[resettable]) { self.array = array }    func resetAll() -> [resettable] {        return array.map( { .reset() } )    }}class dummy: resettable {    func reset() -> resettable {        print("reset one element")        return self    }}let resettableDummy = resettableArray([dummy(),dummy()])resettableDummy.resetAll()
as! resetable }) resetableVIEws.resetAll()
.reset() }) }}

所以我真正希望能够完成的是downcast inputVIEws并调用resetAll().

我试过了:

但它表示不支持使用resetable作为符合resetable的具体类型

如何通过使用resetAll()实现此目的?

解决方法 我希望我已经理解了问题/规格.从Rob NAPIer自由采取,如何:

总结

以上是内存溢出为你收集整理的swift – 无法将数组成员转发协议类型全部内容,希望文章能够帮你解决swift – 无法将数组成员转发为协议类型所遇到的程序开发问题。

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

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

原文地址: http://www.outofmemory.cn/web/999903.html

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

发表评论

登录后才能评论

评论列表(0条)

保存