diff --git a/docs/images/multiplatform-mobile/create-first-app/multiplatform-mobile-upgrade.png b/docs/images/multiplatform-mobile/create-first-app/multiplatform-mobile-upgrade.png index 4f6141a6cac..b12d6e94cf4 100644 Binary files a/docs/images/multiplatform-mobile/create-first-app/multiplatform-mobile-upgrade.png and b/docs/images/multiplatform-mobile/create-first-app/multiplatform-mobile-upgrade.png differ diff --git a/docs/topics/multiplatform-mobile/multiplatform-mobile-setup.md b/docs/topics/multiplatform-mobile/multiplatform-mobile-setup.md index f5d678ae5eb..043ffb37e3c 100644 --- a/docs/topics/multiplatform-mobile/multiplatform-mobile-setup.md +++ b/docs/topics/multiplatform-mobile/multiplatform-mobile-setup.md @@ -107,10 +107,18 @@ To make sure everything works as expected, install and run the KDoctor tool:
  • Make sure that you have Xcode installed. You can get it from its official website.
  • -
  • Launch Xcode in a separate window to accept its license terms and allow it to perform some necessary initial tasks.
  • -
  • -

    Error: can't grab Xcode schemes. If you encounter an error like this, in Xcode, select Settings/Preferences | Locations. In the Command Line Tools field, select your Xcode.

    - Xcode schemes +
  • If you haven't launched Xcode yet, open it in a separate window. Accept the license terms and allow it to perform some necessary initial tasks.
  • +
  • You may encounter Error: can't grab Xcode schemes or other issues regarding command line tools selection. In this case, do one of the following:

    + +
  • In the Terminal, run:

    + sudo xcode-select --switch /Applications/Xcode.app +
  • +
  • Alternatively, in Xcode, select Settings/Preferences | Locations. In the Command Line Tools field, select your Xcode version. + Xcode schemes +

    Make sure that the path to Xcode.app is selected. Confirm the action in a separate window if required.

    +
  • +
    diff --git a/docs/topics/multiplatform-mobile/multiplatform-mobile-update-ui.md b/docs/topics/multiplatform-mobile/multiplatform-mobile-update-ui.md index ccd2b80aec6..b54a1f330d6 100644 --- a/docs/topics/multiplatform-mobile/multiplatform-mobile-update-ui.md +++ b/docs/topics/multiplatform-mobile/multiplatform-mobile-update-ui.md @@ -57,14 +57,14 @@ Make some changes and see how it is reflected in the UI: Here the `LazyColumn` composable shows the list of `Text` items, adds padding around the content and a space between the list items. 5. Follow Android Studio's suggestions to import the missing dependencies. -6. Update the preview as well, passing a list as an argument: +6. Update the preview as well, fixing the issue with the `String` argument: ```kotlin @Preview @Composable fun DefaultPreview() { MyApplicationTheme { - Greeting(listOf("Hello, Android!")) + Greeting() } } ``` diff --git a/docs/topics/multiplatform-mobile/multiplatform-mobile-upgrade-app.md b/docs/topics/multiplatform-mobile/multiplatform-mobile-upgrade-app.md index 519e19c5c0d..3ae15c79365 100644 --- a/docs/topics/multiplatform-mobile/multiplatform-mobile-upgrade-app.md +++ b/docs/topics/multiplatform-mobile/multiplatform-mobile-upgrade-app.md @@ -149,7 +149,7 @@ data class RocketLaunch ( ### Connect HTTP client -1. In `shared/src/commonMain/kotlin`, create a new `RocketComponent` class. +1. In `shared/src/commonMain/kotlin`, create a new `RocketComponent` class in the project folder. 2. Add the `httpClient` property that will be used to retrieve some rocket launch information through an HTTP GET request: ```kotlin @@ -188,7 +188,6 @@ data class RocketLaunch ( 4. Call the `httpClient.get` function to retrieve the information about the rocket launches: ```kotlin - import RocketLaunch import io.ktor.client.request.* private suspend fun getDateOfLastSuccessfulLaunch(): String { @@ -319,7 +318,7 @@ The view model will manage the data from `Activity` and won't disappear when the } ``` -2. In `androidApp/src/main/java`, create a new `MainViewModel` class: +2. In `androidApp/src/main/java`, create a new `MainViewModel` class in the project folder: ```kotlin import androidx.lifecycle.ViewModel @@ -356,12 +355,13 @@ The view model will manage the data from `Activity` and won't disappear when the import kotlinx.coroutines.launch class MainViewModel : ViewModel() { - // ... + // ... - init { - viewModelScope.launch { - Greeting().greet().collect { phrase -> - //... + init { + viewModelScope.launch { + Greeting().greet().collect { phrase -> + //... + } } } } @@ -533,16 +533,20 @@ Now the view model will emit signals whenever this property changes. #### Choose a library to consume flows from iOS In this tutorial, you can choose between the [KMP-NativeCoroutines](https://github.com/rickclephas/KMP-NativeCoroutines) -and [SKIE](https://github.com/touchlab/SKIE/) libraries. Both are open-sources solutions that help work with flows in iOS. -They support cancellation and generics with flows, something that the Kotlin/Native compiler doesn't provide by default yet. +and [SKIE](https://github.com/touchlab/SKIE/) libraries that help work with flows in iOS. Both are open-sources solutions +that support cancellation and generics with flows, something that the Kotlin/Native compiler doesn't provide by default yet. The SKIE library augments the Objective-C API produced by the Kotlin Multiplatform compiler. +SKIE transforms flows into an equivalent of the Swift's `AsyncSequence` structure. +Rather than using a wrapper, it looks like any other Swift library when calling it from Swift. + Using SKIE is less verbose as it doesn't use wrappers around flows. It's easier to set up because it will be part of the framework rather than a dependency that needs to be added as a CocoaPod or SPM file. Apart from flows, SKIE also supports [other features](https://skie.touchlab.co/features/). -The KMP-NativeCoroutines library helps you consume suspending functions and flows from iOS. -It's a more tried-and-tested option, and may be a more stable solution at the moment. +The KMP-NativeCoroutines library helps you consume suspending functions and flows from iOS. It's a more tried-and-tested +option, and may be a more stable solution at the moment. KMP-NativeCoroutines supports of `async`/`await`, Combine, +and RxSwift approaches to concurrency while SKIE supports of `async`/`await` only. #### Option 1. Configure KMP-NativeCoroutines {initial-collapse-state="collapsed"} @@ -668,13 +672,11 @@ It's a more tried-and-tested option, and may be a more stable solution at the mo ![Final results](multiplatform-mobile-upgrade.png){width=500} -> You can find this state of the project in our [GitHub repository](https://github.com/kotlin-hands-on/get-started-with-kmp). -> -{type="note"} + #### Option 2. Configure SKIE {initial-collapse-state="collapsed"} -To set up the library, in `shared/build.gradle.kts`, configure the SKIE plugin and click the **Sync** button. +To set up the library, in `shared/build.gradle.kts`, specify the SKIE plugin and click the **Sync** button. ```kotlin plugins { @@ -696,35 +698,27 @@ plugins { ```Swift func startObserving() { Task { - do { - for try await phrase in Greeting().greet() { - self.greetings.append(phrase) - } - } catch { - print("Failed with error: \(error)") - } - } + for await phrase in Greeting().greet() { + self.greetings.append(phrase) + } + } } ``` -3. Mark `ViewModel` with the `@MainActor` annotation. It ensures all asynchronous operations within `ViewModel` run on - the main thread to comply with Kotlin/Native requirement: +3. Make sure `ViewModel` is marked with the `@MainActor` annotation. It ensures all asynchronous operations within + `ViewModel` run on the main thread to comply with Kotlin/Native requirement: ```Swift // ... extension ContentView { @MainActor class ViewModel: ObservableObject { - @Published var greetings: Array = [] + @Published var greetings: [String] = [] func startObserving() { Task { - do { - for try await phrase in Greeting().greet() { - self.greetings.append(phrase) - } - } catch { - print("Failed with error: \(error)") + for await phrase in Greeting().greet() { + self.greetings.append(phrase) } } } @@ -736,9 +730,7 @@ plugins { ![Final results](multiplatform-mobile-upgrade.png){width=500} -> You can find this state of the project in our [GitHub repository](https://github.com/kotlin-hands-on/get-started-with-kmp). -> -{type="note"} + ## Next step