Hi, I thought I'd ask as this sounds like the perfect use for Swift Macros and I'm betting other people ran into the same issue :)
I'm currently trying to simplify [weak self]
captures in some of my code. For example:
// Usual syntax
someAlert.addTextField { [weak self] textField in
guard let self else { return }
textField.text = somethingInSelf()
}
Adding a macro seems to trade one kind of wordiness for another:
// Using a macro works, but is wordy because it requires non-trailing syntax
someAlert.addTextField(configurationHandler: #weakSelf { textField in
textField.text = somethingInSelf()
})
Ideally I imagine there must be a way to do something like the code below:
// Using the same macro fails when applied to a trailing closure
someAlert.addTextField #weakSelf { textField in
textField.text = somethingInSelf()
}
Does anyone have any suggestions? I feel this is probably a known/solved problem and I'm being a bit slow on the uptake :D