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

概述这段代码崩溃了swift(3,3.1,4)编译器: protocol Test { func f()}let x = Test.f // crash 我希望,也许是天真的,编译器会将x推断为带有签名的函数类型(Test) – > (虚空) – >无效,以后,我可以这样称呼它: let y = SomeClassConformingToTest()x(y)() 我想我的问题是:显然编译 这段代码崩溃了swift(3,3.1,4)编译器:
protocol Test {    func f()}let x = Test.f // crash

我希望,也许是天真的,编译器会将x推断为带有签名的函数类型(Test) – > (虚空) – >无效,以后,我可以这样称呼它:

let y = SomeClassConformingTotest()x(y)()

我想我的问题是:显然编译器应该做除崩溃之外的事情,但Swift目前是否支持这种语法?

如你所说,编译器永远不会崩溃;这确实是一个错误,has been filed here.其中,Swift团队成员Slava pestov说:

We plan on making MyProtocol.someInstanceMethod work. You can already
do this for classes,eg,

06000

It should have the same behavior for protocols:

06001

I plan on addressing this later.

截至2017年5月8日,错误报告现已标记为“进行中”,因此希望这将成为Swift 4.0的发布版本.

但是,在实现/修复之前 – 一个简单的解决方法就是使用闭包表达式,以便充当部分应用方法的thunk,并使用实例调用它:

protocol Test {    func f()}struct S : Test {    func f() {        print("hello")    }}let x: (Test) -> () -> VoID = { 
let x: (Test) -> VoID = { [+++].f() }let s = S()x(s) // "hello"
.f }let s = S()x(s)() // "hello"

当然,如果你不需要中间部分应用功能,你可以说:

[+++] 总结

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

概述这段代码崩溃了swift(3,3.1,4)编译器: protocol Test { func f()}let x = Test.f // crash 我希望,也许是天真的,编译器会将x推断为带有签名的函数类型(Test) – > (虚空) – >无效,以后,我可以这样称呼它: let y = SomeClassConformingToTest()x(y)() 我想我的问题是:显然编译 这段代码崩溃了swift(3,3.1,4)编译器:
protocol Test {    func f()}let x = Test.f // crash

我希望,也许是天真的,编译器会将x推断为带有签名的函数类型(Test) – > (虚空) – >无效,以后,我可以这样称呼它:

let y = SomeClassConformingTotest()x(y)()

我想我的问题是:显然编译器应该做除崩溃之外的事情,但Swift目前是否支持这种语法?

如你所说,编译器永远不会崩溃;这确实是一个错误,has been filed here.其中,Swift团队成员Slava pestov说:

We plan on making MyProtocol.someInstanceMethod work. You can already
do this for classes,eg,

06000

It should have the same behavior for protocols:

06001

I plan on addressing this later.

截至2017年5月8日,错误报告现已标记为“进行中”,因此希望这将成为Swift 4.0的发布版本.

但是,在实现/修复之前 – 一个简单的解决方法就是使用闭包表达式,以便充当部分应用方法的thunk,并使用实例调用它:

protocol Test {    func f()}struct S : Test {    func f() {        print("hello")    }}let x: (Test) -> () -> VoID = { 
let x: (Test) -> VoID = { .f() }let s = S()x(s) // "hello"
.f }let s = S()x(s)() // "hello"

当然,如果你不需要中间部分应用功能,你可以说:

[+++] 总结

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

概述这段代码崩溃了swift(3,3.1,4)编译器: protocol Test { func f()}let x = Test.f // crash 我希望,也许是天真的,编译器会将x推断为带有签名的函数类型(Test) – > (虚空) – >无效,以后,我可以这样称呼它: let y = SomeClassConformingToTest()x(y)() 我想我的问题是:显然编译 这段代码崩溃了swift(3,3.1,4)编译器:
protocol Test {    func f()}let x = Test.f // crash

我希望,也许是天真的,编译器会将x推断为带有签名的函数类型(Test) – > (虚空) – >无效,以后,我可以这样称呼它:

let y = SomeClassConformingTotest()x(y)()

我想我的问题是:显然编译器应该做除崩溃之外的事情,但Swift目前是否支持这种语法?

如你所说,编译器永远不会崩溃;这确实是一个错误,has been filed here.其中,Swift团队成员Slava pestov说:

We plan on making MyProtocol.someInstanceMethod work. You can already
do this for classes,eg,

06000

It should have the same behavior for protocols:

06001

I plan on addressing this later.

截至2017年5月8日,错误报告现已标记为“进行中”,因此希望这将成为Swift 4.0的发布版本.

但是,在实现/修复之前 – 一个简单的解决方法就是使用闭包表达式,以便充当部分应用方法的thunk,并使用实例调用它:

protocol Test {    func f()}struct S : Test {    func f() {        print("hello")    }}let x: (Test) -> () -> VoID = { 
let x: (Test) -> VoID = { .f() }let s = S()x(s) // "hello"
.f }let s = S()x(s)() // "hello"

当然,如果你不需要中间部分应用功能,你可以说:

总结

以上是内存溢出为你收集整理的从swift协议存储/传递函数类型全部内容,希望文章能够帮你解决从swift协议存储/传递函数类型所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存