Unwrapping weak self in closure causes compilation error
| Originator: | josh.hinman | ||
| Number: | rdar://17650278 | Date Originated: | 11-Jul-2014 09:14 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6.0b3 (6A254o) |
| Classification: | Reproducible: | Always |
Summary:
When specifying a weak self in a closure (e.g. [weak self] in), trying to unwrap self and call a method on an ivar (self?.ivar.method()) fails to compile.
Steps to Reproduce:
1. Open a new Swift file and enter this code:
class Foo
{
func hello()
{
println("hello world")
}
}
class Bar
{
func call(c: () -> ())
{
c()
}
}
class X
{
var f = Foo()
func abc() {
var bb = Bar()
bb.call {
[weak self] in
self?.f.hello()
}
}
}
var y = X()
y.abc()
Expected Results:
The program should compile, and when run, should output "hello world"
Actual Results:
error: could not find member 'hello'
bb.call {
~~~^~~~~~
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!