Ok, looks like we have a decision. Let's move on to the question of the calling super
initialiser for anonymous classes.
Few ideas from me:
Given these declarations:
let scrollView: UIScrollView = ...
let data: DataModel = ...
let lastOffset: CGPoint = ...
Option A
Explicit init method with no parameters
let delegate = class DelegateBase & UIScrollViewDelegate {
// Shadows `lastOffset` from the parent scope, `lastOffset` from the parent scope is not captured
var lastOffset: CGPoint
// Must be without parameters, because parameters are defined implicitly by capturing variables from the context
init() {
// But we can still initialise extra properties
lastOffset = .zero
super(data: data)
}
override func reset() {
scrollView.contentOffset = lastOffset
/// Should we also allow `self.scrollView`?
/// Probably not:
/// * `scrollView` should be mentioned without `self.` at least once to be captured
/// * Since stored properties are also accessible without `self.`, this creates a contracting logic:
/// - there is no property `scrollView`, so this name captures `scrollView` from the parent context
/// - but to capture it `scrollView` we need to make a property with name `scrollView`
/// - but then `scrollView` refers to the property
/// - so `scrollView` from the parent context is not captured
/// - so there there should be not property for `scrollView`
/// * not allowing leaves some room to change how captured variables are stored and named.
self.scrollView.flashScrollIndicators()
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
...
}
}
Option B
Explicit init method even without parenthesis - extra work to do in parser when implementing
let delegate = class DelegateBase & UIScrollViewDelegate {
var lastOffset: CGPoint
init {
lastOffset = .zero
super(data: data)
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
}
}
Option C
Call to super
directly inside the class body
let delegate = class DelegateBase & UIScrollViewDelegate {
super(data: data)
var lastOffset: CGPoint = .zero
func scrollViewDidScroll(_ scrollView: UIScrollView) {
}
}
Option D
Capture-list-like
let delegate = class DelegateBase & UIScrollViewDelegate { super(data: data) in
var lastOffset: CGPoint = .zero
func scrollViewDidScroll(_ scrollView: UIScrollView) {
}
}
Option E
Inside capture list
let delegate = class DelegateBase & UIScrollViewDelegate { [unowned scrollView, super(data: data)] in
var lastOffset: CGPoint = .zero
func scrollViewDidScroll(_ scrollView: UIScrollView) {
}
}
Option F
Java-like, after class name
let delegate = class DelegateBase(data: data) & UIScrollViewDelegate {
var lastOffset: CGPoint = .zero
func scrollViewDidScroll(_ scrollView: UIScrollView) {
}
}
Option G
Java-like, after class and all protocols
let delegate = class (DelegateBase & UIScrollViewDelegate)(data: data) {
var lastOffset: CGPoint = .zero
func scrollViewDidScroll(_ scrollView: UIScrollView) {
}
}
My personal preference are A and D.