OSLog capture semantics

If I write:

Logger().log("Log this value: \(myInstanceProperty)")

I get "Reference to property 'myInstanceProperty' in closure requires explicit use of 'self' to make capture semantics explicit."

This seems to imply an escaping autoclosure, which means we must guard against retaining self.

Is this correct or is it safe to include a strong self here?

Accepted Reply

is it safe to include a strong self here?

This.

The autoclosure has to be escaping due to the way things are implemented internally but the closure will be released before the log(…) call is done.

We already have a bug on file requesting improvements in this space (r. 73459748).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • Awesome, thanks Quinn!

Add a Comment

Replies

is it safe to include a strong self here?

This.

The autoclosure has to be escaping due to the way things are implemented internally but the closure will be released before the log(…) call is done.

We already have a bug on file requesting improvements in this space (r. 73459748).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • Awesome, thanks Quinn!

Add a Comment