In Java there is a pattern where a delegate can be declared in-line, instead of making the parent class conform to the interface:
For example:
public class MyClass {
interface Delegate {
void completion(Boolean succeeded);
}
void doSomething(Delegate delegate) {
delegate.completion(true);
}
void myMethod() {
doSomething(new Delegate() { // <-- declared in-line
@Override
public void completion(Boolean succeeded) {
// ...
}
});
}
}
In Swift I can make MyClass
conform to the Delegate
protocol and override the delegate methods on the class level. How can I do that in-line like in the Java pattern?