Hey Ballast, I am trying to share my contract betw...
# ballast
r
Hey Ballast, I am trying to share my contract between iOS and Android. Currently got Android working, and iOS building successfully, but I am getting run time issues with iOS. I am getting
Thread 1: signal SIGABRT
when I run the iOS app on the following line
Copy code
@ObservedObject
    var observableModel = BallastObservable<
    WeatherReportContract.Inputs,
    WeatherReportContract.Events,
    WeatherReportContract.ViewState>(
        viewModelFactory: {KotlinDependencies.shared.getWeatherReportViewModel()}                                
//Highlights getWeatherReportViewModel
    )
I also get
Thread 1: signal SIGABRT
In the combine adapter used in the KaMPKit-ballast project
self.vmState = self.viewModelFactory().initialState //Line 58 highlights viewModelFactory
This is the contract I am using:
Copy code
object WeatherReportContract {
    data class ViewState(
        val weatherReport: WeatherReport = WeatherReport(),
        val isLoading: Boolean = false,
        val errorMessage: String = ""
    ){
        override fun toString(): String {
            return "ViewState(" +
                "Weather Report=${weatherReport::class.simpleName}, " +
                "error=$errorMessage, " +
                "isLoading=$isLoading" +
                ")"
        }
    }

    sealed class Inputs {
        object GetWeatherReport : Inputs()
        object ShowLoading : Inputs()
        object StopLoading : Inputs()
    }

    sealed class Events {

    }
}
This is the iOSViewModel being used:
Copy code
class WeatherReportViewModel(
    weatherUseCase: WeatherUseCase,
    configBuilder: BallastViewModelConfiguration.Builder
) : IosViewModel<
    WeatherReportContract.Inputs,
    WeatherReportContract.Events,
    WeatherReportContract.ViewState
    >(
    config = configBuilder
        .forViewModel(
            initialState = WeatherReportContract.ViewState(),
            inputHandler = WeatherReportInputHandler(weatherUseCase),
            name = "WeatherReport"
        )
)
This is the SwiftUI page:
Copy code
import Combine
import SwiftUI
import shared

private let log = koin.loggerWithTag(tag: "ViewController")

struct WeatherReportView: View {
  @ObservedObject
  var observableModel = BallastObservable<
  WeatherReportContract.Inputs,
  WeatherReportContract.Events,
  WeatherReportContract.ViewState>(
    viewModelFactory: {KotlinDependencies.shared.getWeatherReportViewModel()}
  )
   
  var body: some View {
    WeatherReportContent(
      vmState: observableModel.vmState,
      postInput: observableModel.postInput
    ).withViewModel(observableModel){
      observableModel.postInput(WeatherReportContract.InputsGetWeatherReport())
    }
  }
}

struct WeatherReportContent: View {
  var vmState: WeatherReportContract.ViewState
  var postInput: (WeatherReportContract.Inputs) -> Void
  var body: some View {
    HStack(alignment: .center) {
      VStack {
        Text(vmState.weatherReport.cityTitle ).bold().font(TextStyle.headline.getFont())
        Text(vmState.weatherReport.countryTitle ).bold()
        Divider()
        HStack(spacing: HorizontalSpacings.x10) {
          Text(vmState.weatherReport.temperature )
          Text(vmState.weatherReport.humidity )
        }
            .padding(SurroundingSpacings.large)
        HStack(spacing: HorizontalSpacings.x10) {
          Text(vmState.weatherReport.windSpeed )
          Text(vmState.weatherReport.airPressure )
        }
            .padding(SurroundingSpacings.large)
      }
          .multilineTextAlignment(.center)
      if vmState.isLoading {Text("Loading...")}
    }
        .font(TextStyle.body.getFont())
  }
}
Here is the project branch, if you guys need a deeper look. Any help is greatly appreciated!
c
I think you need to enable to new Kotlin Native memory model in the project, which is done by adding
kotlin.native.binary.memoryModel=experimental
to `gradle.properties. Here’s the official documentation for the new memory model as well https://github.com/JetBrains/kotlin/blob/master/kotlin-native/NEW_MM.md#enable-the-new-mm
r
I just modified the gradle.properties, but unfortunately I am facing the same bugs. Commit in which I modified the gradle.properties.
c
Hmm, I’m not sure what’s going on then. If you clone and run the KaMPKit-ballast repo directly, does it still give the same error?
r
No it doesn't