inut参数在闭包中崩溃Swift编译器 [英] inout parameter in closure crashes the Swift compiler
本文介绍了inut参数在闭包中崩溃Swift编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所有我需要做的是在Swift中启动一个新项目,并添加到 main.swift
All I need to do is start a new project in Swift and add to main.swift
struct Foo {
let bar: (inout baz: String) -> ()
}
当我尝试构建时,我得到一个错误:
由于信号命令失败:分段故障:11
When I try to build I get an error:
Command failed due to signal: Segmentation fault: 11
我做错了什么?
Am I doing anything wrong?
我认为不支持闭包中的 inout
参数,但是如果我定义一个闭包像这样:
I thought that perhaps inout
parameters in closures are not supported, but if I define a closure like so:
let baz: (inout baz: String) -> () = { baz in
baz += "x"
return
}
甚至
var baz: (inout baz: String) -> ()?
它编译并运行OK
推荐答案
只是测试它在Swift 1.2随Xcode 6.3测试版,它编译成功。
所以这绝对是一个编译器的错误,他们在上一个版本
Just tested it in Swift 1.2 shipped with Xcode 6.3 beta, and it compiled successfully. So it was definitely a bug on the compiler that they solved in the last release
这篇关于inut参数在闭包中崩溃Swift编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文