Thomas
06/05/2019, 1:54 PMstruct MyStruct : KotlinInterface {
}
And in Kotlin:
interface KotlinInterface {
...
}
I tried this but it gives the following error:
Non-class type 'MyStruct' cannot conform to class protocol 'KotlinInterface'
svyatoslav.scherbina
06/05/2019, 1:55 PMThomas
06/05/2019, 1:59 PMstruct
and I want it to implement a Kotlin interface. (MVP, where the struct is the V)Thomas
06/05/2019, 2:05 PMsvyatoslav.scherbina
06/05/2019, 2:14 PMkpgalligan
06/05/2019, 3:57 PMThomas
06/05/2019, 4:53 PMinterface MainScreen {
/**
* On Android the View is a Fragment (in Kotlin/Java).
* On iOS the View is a UIViewController (in Swift).
*
* The view has commands to update the UI. These functions are called from the Presenter.
*/
interface View : MvpView {
fun setText(text: String)
}
/**
* Presenter is implemented completely in Kotlin. It receives events from the View, like onButtonClicked.
*/
interface Presenter : MvpPresenter<View> {
fun onButtonClicked()
}
}
This way I can share as much code as possible between Android/iOS. The “View” interface just gets commands to update the UI. I’m currently implementing the Kotlin MainScreen.View
interface in the UIViewController
.
I’m now looking into the new SwiftUI which is a very good improvement over the UIViewController/storyboard. The SwiftUI view is not created as a class but as a struct. Something like this:
struct MainView : View {
var body: some View {
Text("Hello world!")
}
}
I need to find a way to change the text from the Presenter, via the View interface. As this is a struct, I cannot implement the MainScreen.View
interface.
I’m currently exploring other options. The SwiftUI also has a class BindableObject
(with EnvironmentObject
annotation). (See Section 4/5 at https://developer.apple.com/tutorials/swiftui/handling-user-input). This is a class
, so I can implement a Kotlin interface. This might do what I need and I am currently looking into it.
Let me know if you would like to see more details.Sam
06/05/2019, 5:26 PMThomas
06/05/2019, 5:51 PMBindableObject
? https://developer.apple.com/documentation/swiftui/bindableobject
(See Section 4/5 at https://developer.apple.com/tutorials/swiftui/handling-user-input)Sam
06/05/2019, 5:55 PM