Skip to content

Instantly share code, notes, and snippets.

@tapthaker
Last active January 6, 2021 13:58
Show Gist options
  • Save tapthaker/3efc6d706840ea369e4e037a17f6ec9d to your computer and use it in GitHub Desktop.
Save tapthaker/3efc6d706840ea369e4e037a17f6ec9d to your computer and use it in GitHub Desktop.
SR_8536_access_member_in_closure.swift
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