I am trying to do some Android programming with Silver, and one item I cannot figure out is how to create an anonymous local class to handle a multi-method listener. I know that the single method version works with a shortcut so only the lambda is needed, like so:
button.setOnClickListener { view in
self.alert(message: "This is a message to show in the Alert - via Extension")
}
But for example a SeekBar.OnSeekBarChangeListener ? How would that be coded? In Kotlin we can do this:
val listener = object: SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Bool) {
}
override fun onStartTrackingTouch(seekBar: SeekBar) {
}
override fun onStopTrackingTouch(seekBar: SeekBar) { {
}
}
To answer my own question, after some research: Swift - and thus Silver I expect - does not support anonymous inline classes like the example in Kotlin. Instead, a regular inner class can used just as well. For example, this works for me:
It does, although the syntax takes some getting used to and could be improved upon. i’m away from my main computer right now, but i’ll try to get you an example from one of my own projects, tomorrow.