Last active
January 6, 2021 13:58
-
-
Save tapthaker/3efc6d706840ea369e4e037a17f6ec9d to your computer and use it in GitHub Desktop.
SR_8536_access_member_in_closure.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
var bar: (() -> ())? | |
let x = 1 | |
init() { | |
bar = { | |
print(x) # Fix it by changing this to: print(self.x) | |
} | |
} | |
} | |
/* Error | |
capturing_args.swift:8:13: error: reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit | |
print(x) | |
^ | |
capturing_args.swift:8:13: note: reference 'self.' explicitly | |
print(x) | |
^ | |
self. | |
capturing_args.swift:7:11: note: capture 'self' explicitly to enable implicit 'self' in this closure | |
bar = { | |
^ | |
[self] in | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment