<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sammuigai on Medium]]></title>
        <description><![CDATA[Stories by Sammuigai on Medium]]></description>
        <link>https://medium.com/@sammuigai880?source=rss-3a96954d0509------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_QiFlhZlOR0DvxldCOA26g.jpeg</url>
            <title>Stories by Sammuigai on Medium</title>
            <link>https://medium.com/@sammuigai880?source=rss-3a96954d0509------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 00:13:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sammuigai880/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Native at heart: Mixing SwiftUi with Compose Multiplatform]]></title>
            <link>https://sammuigai880.medium.com/native-at-heart-mixing-swiftui-with-compose-multiplatform-b50b51f1ba6d?source=rss-3a96954d0509------2</link>
            <guid isPermaLink="false">https://medium.com/p/b50b51f1ba6d</guid>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[compose-multiplatform]]></category>
            <dc:creator><![CDATA[Sammuigai]]></dc:creator>
            <pubDate>Tue, 03 Jun 2025 12:00:27 GMT</pubDate>
            <atom:updated>2025-06-04T07:47:50.337Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*74NHJIPECCK9ykv5hNBqeQ.png" /></figure><p>With Compose Multiplatform now stable for IOS, it’s an encouraging time for developers to consider using it in production. While CMP allows for sharing UI code across platforms, there are situations where incorporating native UI code becomes necessary. In this article, we’ll explore the reasons for using SwiftUI within your project and demonstrate how to integrate it effectively.</p><h4>Why?</h4><p>While there aren’t many reasons to use native UI when working with Compose Multiplatform, one of the most common is the need to integrate libraries that don’t support Compose Multiplatform. Some libraries depend heavily on the native UI framework of their respective platforms, leaving developers with no choice but to use native UI components. A good example of this is the Stripe payment library, among others.</p><h4>Let’s get started</h4><p>According to the documentation, there is an way to implement this — you can check it out <a href="https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-swiftui-integration.html#use-swiftui-inside-compose-multiplatform">here</a>. While the approach works, I believe it can become problematic as the app grows, especially if multiple native UI components are needed in different parts of the app. This is because it would require passing all these components down through the composable hierarchy, which can clutter the parameter lists and reduce code readability.</p><p>In the section below, we’ll explore an alternative approach that helps keep the codebase clean and scalable.</p><p>In a new Compose Multiplatform project, we expose the App() composable to iOS via a UIViewController.</p><pre>import androidx.compose.ui.window.ComposeUIViewController<br><br>fun MainViewController() = ComposeUIViewController { App() }</pre><p>The ComposeUiViewController function returns a UIViewController, which is a UIKit component. From the iOS side, we can access this function to embed the Compose UI.</p><pre>import UIKit<br>import SwiftUI<br>import ComposeApp<br><br>struct ComposeView: UIViewControllerRepresentable {<br>    func makeUIViewController(context: Context) -&gt; UIViewController {<br>        MainViewControllerKt.MainViewController()<br>    }<br><br>    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}<br>}</pre><p>In the above code, we call the MainViewController function inside makeUIViewController. This function is part of the UIViewControllerRepresentable protocol (interface), so we are providing its implementation here. UIViewControllerRepresentable acts as a bridge, allowing us to integrate UIKit with SwiftUI. Therefore, ComposeView is a SwiftUI component.</p><p>With this in mind, let’s see how we can access a SwiftUI component to create a multiplatform UI.</p><p>For this example, we’ll use a button. To access the button across platforms, we can follow the <em>expect/actual</em> pattern. On the Android side, we can implement the button using standard Jetpack Compose.</p><pre>// Common code<br>@Composable<br>expect fun NativeButton(modifier: Modifier = Modifier, onClick: () -&gt; Unit)<br><br>// Android<br>@Composable<br>actual fun NativeButton(modifier: Modifier,onClick: () -&gt; Unit) {<br>    Button(<br>        onClick = onClick,<br>        modifier = modifier<br>    ) {<br>        Text(&quot;HELLO FROM ANDROID&quot;)<br>    }<br>}<br><br>// Ios<br>@Composable<br>actual fun NativeButton(modifier: Modifier,onClick: () -&gt; Unit) {<br>    // Implementation goes here<br>}</pre><p>We can only access SwiftUI as a UIKit component within Compose. Therefore, we can provide an interface that will be implemented in Swift code, with methods that return a UIViewController.</p><pre>interface NativeViewFactory {<br>    fun nativeButtonView(onClick: () -&gt; Unit): UIViewController<br>}</pre><p>In the swift code we can provide the implementation as shown below:</p><pre>struct NativeButton:View {<br>    let onClick:() -&gt; Void<br>    var body: some View {<br>        Button(action: onClick,label: {<br>            Text(&quot;HELLO FROM IOS&quot;)<br>                .padding(16)<br>                .background(Color.red)<br>                <br>        })<br>    }<br>}<br><br>class NativeViewFactoryImpl: NativeViewFactory {<br>    func nativeButtonView(onClick: @escaping () -&gt; Void) -&gt; UIViewController {<br>       UIHostingController(rootView: NativeButton(onClick: onClick))<br>    }<br>}</pre><p>In the code, we provide the implementation of NativeViewFactory and use UIHostingController, which helps convert SwiftUI views to UIKit. Now, we need to provide NativeViewFactory within our App() so that we can easily use the views wherever needed. We take advantage of CompositionLocals to achieve this. You can learn more about CompositionLocals <a href="https://developer.android.com/develop/ui/compose/compositionlocal">here</a>.</p><p>We pass the implementation of NativeViewFactory to the MainViewController function and use CompositionLocalProvider to inject the provided nativeViewFactory into the Compose hierarchy, making it accessible deeper in the UI tree.</p><pre>fun MainViewController(<br>    nativeViewFactory: NativeViewFactory<br>): UIViewController = ComposeUIViewController(<br>    content = {<br>        CompositionLocalProvider(LocalNativeViewFactory provides nativeViewFactory){<br>            App()<br>        }<br>    }<br>)<br><br>val LocalNativeViewFactory = compositionLocalOf&lt;NativeViewFactory&gt; { error(&quot;NativeViewFactory not provided&quot;) }<br><br>interface NativeViewFactory {<br>    fun nativeButtonView(onClick: () -&gt; Unit): UIViewController<br>}</pre><p>We can now retrieve the injected NativeViewFactory from the CompositionLocal and use it in the UIKitViewController composable function. UIKitViewController is a helper that embeds a UIViewController inside Compose.</p><pre>// Ios<br>@Composable<br>actual fun NativeButton(modifier: Modifier,onClick: () -&gt; Unit) {<br>    val factory = LocalNativeViewFactory.current<br>    UIKitViewController(<br>        factory = { factory.nativeButtonView(onClick = onClick) },<br>        modifier = modifier<br>            .fillMaxWidth()<br>            .height(50.dp),<br>    )<br>}</pre><p>When we call the MainViewController function in Swift, we can now provide the implementation of the NativeViewFactory.</p><pre>struct ComposeView: UIViewControllerRepresentable {<br>    func makeUIViewController(context: Context) -&gt; UIViewController {<br>        MainViewControllerKt.MainViewController(nativeViewFactory: NativeViewFactoryImpl())<br>    }<br>    <br>    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}<br>}</pre><p>And just like that, we can use a SwiftUI view in a Compose Multiplatform app. This makes it easier to add new SwiftUI views whenever needed. Thank you so much for reading! If you found this helpful, don’t forget to leave a clap.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b50b51f1ba6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Gentle Introduction To Kotlin Scope Functions.]]></title>
            <link>https://sammuigai880.medium.com/a-gentle-introduction-to-kotlin-scope-functions-7a4e3301cdfa?source=rss-3a96954d0509------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a4e3301cdfa</guid>
            <dc:creator><![CDATA[Sammuigai]]></dc:creator>
            <pubDate>Tue, 16 Jan 2024 03:41:42 GMT</pubDate>
            <atom:updated>2024-01-16T03:41:42.477Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the cool features that Kotlin has is scope functions.Scope functions are simply functions that execute a block of code within the context of a given object. In this article we are going to take a look at four of the most commonly used scope functions in Kotlin that is let, run , apply and also.</p><h4>let</h4><p>let function is used mostly in a situation where there is need to perform a null check. It creates a new scope that lets you perform operations safely.let provides you the instance of the class you called it on as it inside the block ie references to the object it is called upon as lambda argument. It might also returns a value which is not necessarily of the same type as the object it is called on eg it might be called on a string and it returns a boolean like in the example below. For this reason it is considered a transformational function.</p><pre>class School {<br>    var name: String? = &quot;Daystar&quot;<br>        private set<br><br>    var location = &quot;Nairobi&quot;<br><br>    val noOfStudents = 320<br><br>    val averagePerformance = 9.6<br><br>    fun notKnown() {<br>        name = null<br>    }<br>}<br><br>/*<br>* A function to print the name of the school<br>* */<br><br>fun printSchoolName(school: School) {<br><br>    // Inside the let scope ,the value it holds the name value of type String not String?<br>    // Hence, it will only be executed if and only if name does not contain a null value<br>    // Elvis operator can be used to execute a certain piece of code given name is holding a null value<br>    // in this case just printing Null value<br>    school.name?.let {<br>        println(it)<br>    } ?: println(&quot;Null value\n&quot;)<br><br>    // Call the function notKnown to set the value of name back to null<br>    school.notKnown()<br><br>    // Null value should now be printed since name is null<br>    school.name?.let {<br>        println(it)<br>    } ?: println(&quot;Null value\n&quot;)<br><br>    // let also allows returning a value which is not necessarily the same to the one it is called upon<br>    val isDaystar = school.name?.let {<br>        it == &quot;Daystar&quot;<br>    }<br>    println(isDaystar)<br>}<br><br>fun main() {<br>    val school = School()<br>    printSchoolName(school)<br>}</pre><h4>run</h4><p>run is has the same functionality as let but the only difference is that it concentrates more on target object ie, inside the scope it provides the target object as this (lambda receiver). Just like let it can return a value which is not necessarily the same as the type as the object it is called upon hence still consider transformational function.</p><p>In alot of cases it is not necessary to use this while access the properties of the receiver object. The example below uses the school class in the previous example.</p><pre>fun printSchool(school: School?) {<br><br>    // By using safe call ? we ensure that school is not null<br>    // run gives us a scope which use to access the properties of the class it is called upon<br>    // in this case using lambda receiver(this)<br>    school?.run {<br>        val location = this.location<br>        println(location)<br>        val performance = this.averagePerformance<br>        println(performance)<br>    }<br><br>    println(&quot;\n&quot;)<br><br>    // Since we are inside the scope of school it is not necessary to access the properties using this keyword<br>    // We can access them directly as they are<br>    school?.run {<br>        println(location)<br>        println(averagePerformance)<br>    }<br><br>    // Just like let run can return a value which is not necessarily of the same class as the one it is called on<br>    val isInNairobi = school?.run {<br>        location == &quot;Nairobi&quot;<br>    }<br>run<br>    println(isInNairobi)<br><br><br>}</pre><h4>also</h4><p>also function operate in the same manner as let, the only difference being that it is not transformational meaning that it can only return the object it is called upon. While this does not mean that the object is unmodified thus it can be called on an object, modify it and then return it. This can come in handy when you need to chain multiple operations eg scope functions as shown in the example below.</p><pre>fun printSchoolName2(school: School){<br>    //Similar to let<br>    school.name?.also {<br>        println(it)<br>    }<br><br>    val isDayStar = school.name?.also {<br>        //Compiler complains saying that the expression is unused since it cannot be returned<br>        it == &quot;DayStar&quot;<br>    }<br><br>    // school.also { it.notKnown()} returns a school object that is modified<br>    // this can then be chained together with let function and since let is transformational it can return a<br>    // boolean<br>    val isNameNull = school.also {<br>        it.notKnown()<br>    }.let {<br>        it.name != null<br>    }<br><br>    // Prints out false since school is modified and name is set to null<br>    println(isNameNull)<br>}</pre><h4>apply</h4><p>apply function is also not a transformational function hence it has to return the same object it is called on. But just like run function, it references to the object it called upon as a lambda receiver(this).</p><p>Here is an example of how apply can be used.</p><pre>fun printSchool2(school: School?) {<br><br>    school?.apply {<br>        val location = this.location<br>        println(location)<br>        val performance = this.averagePerformance<br>        println(performance)<br>    }<br><br>    println(&quot;\n&quot;)<br><br>    school?.apply {<br>        println(location)<br>        println(averagePerformance)<br>    }<br><br>    // Just like let also it cannot a different type to the one it is called upon<br>    val isInNairobi = school?.apply {<br>        //Compiler complains saying that the expression is unused since it cannot be returned<br>        location == &quot;Nairobi&quot;<br>    }<br><br><br>}</pre><p>That’s it for now. I hope I helped you get a better understanding of how scope functions work in Kotlin. Another scope function you can take a look at is with which works a bit differently from the scope functions discussed above.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a4e3301cdfa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DroidconKe 2023: My Top TakeAways]]></title>
            <link>https://sammuigai880.medium.com/droidconke-2023-my-top-takeaways-f6129a3a9f8b?source=rss-3a96954d0509------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6129a3a9f8b</guid>
            <category><![CDATA[droidcon]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[compose-multiplatform]]></category>
            <dc:creator><![CDATA[Sammuigai]]></dc:creator>
            <pubDate>Wed, 15 Nov 2023 09:13:54 GMT</pubDate>
            <atom:updated>2023-11-15T09:13:54.213Z</atom:updated>
            <content:encoded><![CDATA[<p>This year marks the first time I attended the DroidConKe conference. I was filled with excitement and anticipation, eager to listen to the sessions and connect with other Android developers. In this article, I will share my top takeaways from the sessions I attended.</p><h4>Mastering Android Build Variant</h4><p>This was the first technical session I attended. It was led by Alpha Omondi. He introduced us to the concept of build variants and provided examples of applications that might utilize different build variants of the same application. Build variants are simply different versions of the same application. I learned that in order to create build variants, we need to utilize build types and product flavors. Build types define how the application is packaged, while product flavors define what features and resources are included in the application. Combining different build types and product flavors results in different versions of the application. It was a very interesting talk, and I learned a lot of new things that I honestly did not know before.</p><h4>Kt-pub : A compose Multiplatform Story for Kotlin Developers</h4><p>This session was led by Ian Okumu, a senior technical mentor at Moringa School. He also runs a YouTube channel where he provides Kotlin tutorials, which you can check out <a href="https://www.youtube.com/@kt_whisperer">here</a>. In this session, he shared his experience developing Kt-pub, an app for sharing Kotlin jobs. He leveraged Compose Multiplatform, which enabled him to share not only the logic code but also some of the UI code. It was during this session that I learned that Compose Multiplatform can run on the web in two ways: Compose for Web, which is based on Kotlin WASM, and Compose HTML, which allows you to write HTML-like code in Compose. Kt-pub runs smoothly on both desktop applications and Android. While we couldn’t test it on an iOS device since Ian didn’t have a macOS laptop, we believe it would still work. Ian promised to launch the application when the K2 Compiler is released, and I honestly can’t wait.</p><h4>Best Practices for Developing Amazing Kotlin Multiplatform Apps</h4><p>This was one of the most interesting sessions I attended. It was led by Pamela Hill, a developer advocate at JetBrains. She gave a brief overview of the history of Kotlin Multiplatform and then introduced us to the project structure of a Kotlin Multiplatform project. It was fascinating to see the app running on iOS devices, Android devices, and desktop applications.</p><p>Pamela shared some of the best practices for developing Kotlin Multiplatform applications, especially when accessing platform-specific APIs. One approach is to use the expect modifier for functions that will have different implementations on each platform and then have an actual modifier for the function in each platform. Another way is to use an interface that will have different implementations on each platform in a dependency injection (DI) pattern.</p><p>Pamela also discussed how to call suspending functions in Swift when sharing logic but not the UI. This session was very informative and provided a glimpse into the future of Kotlin Multiplatform.</p><h4>Android Modularization: Who need structure anyway</h4><p>This session was led by Brian Mambo, an Android engineer at Baobab Circle. He discussed the reasons why we need to modularize an application. When modularizing, it’s essential to ensure low coupling and high cohesion.</p><p>Low coupling is crucial for ensuring that modules are as independent as possible, minimizing the impact of changes in one module on others. High cohesion, on the other hand, ensures that modules have code that acts as a system, with clearly defined responsibilities and adherence to boundaries.</p><p>Brian presented two approaches to modularization: feature-based and layer-based. He discussed the pros and cons of each approach, highlighting their limitations. To address these limitations, he introduced modularization by both features and layers, a hybrid approach that combines the advantages of both feature-based and layer-based modularization.</p><h4>Conclusion</h4><p>While all the sessions presented were impactful, I must conclude my coverage here. The whole event was so impactful for me as an upcoming developer. I learned a lot, and I look forward to applying the information I gained to the projects I am working on.I hope this glimpse into a few of the sessions has given you a sense of the breadth and depth of knowledge shared at this year’s meetup. Once again, a big thank you to the Droidconke organizing team for making this experience possible.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6129a3a9f8b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin syntax, outputs, comments and variables.]]></title>
            <link>https://sammuigai880.medium.com/kotlin-syntax-outputs-comments-and-variables-9d456ec5feff?source=rss-3a96954d0509------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d456ec5feff</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Sammuigai]]></dc:creator>
            <pubDate>Wed, 01 Nov 2023 17:27:01 GMT</pubDate>
            <atom:updated>2023-11-01T17:27:01.809Z</atom:updated>
            <content:encoded><![CDATA[<p>Kotlin is a modern, open-source, statically-typed programming language that runs on the Java Virtual Machine (JVM) and can also be compiled to native code. It was first introduced in 2011 and has gained significant popularity in the software development community since then. In this article we will get a brief introduction of how Kotlin Syntax varies compared to other languages as well as explore other features such as outputs, comments and variables.</p><h3>Kotlin Syntax</h3><p>Kotlin has a unique syntax compared to most of popular languages being used today. Lets take a look at some of the common features which are quite unique in Kotlin.</p><ol><li><strong>Semicolon : </strong>Unlike others popular languages,semicolons are not required at the end of the statement. This feature makes the code less error prone.Omitting semicolons eliminates the possibility of accidentally inserting them in the wrong places or forgetting to include them when necessary.</li></ol><pre>fun main(){<br>  println(&quot;Hello World&quot;) //No need to terminate the statement with a semicolon<br>  println(&quot;Kotlin is fun&quot;)<br>}</pre><p>2. <strong>Type Inference </strong>: Kotlin has a strong type inference. This means you don’t need to explicitly declare variable types as you declare them. The compiler will automatically infer the type based on the context.</p><pre>fun main(){<br>  val language=&quot;Kotlin&quot; //Compiler automatically assigns type String upon initialisation <br>}</pre><p>3. <strong>Null safety : </strong>Kotlin enforces null safety. Variables are non-null by default. To allow null values you need to use nullable types explicitly by adding ? suffix.</p><pre>fun main(){<br> val name:String? = null //By adding ? suffix we can assign the variable name with a null value<br>}</pre><p>4. <strong>Functional Syntax : </strong>In Kotlin, functions are defined using the fun keyword, and the return type comes after a colon. Functions are first-class citizens, which means they can be assigned to variables, passed as arguments, and returned from other functions.</p><pre>fun main(){<br>    // add() function can be assignned to the variable output<br>    val output = add(3,4)<br>    println(output)<br>}<br><br>fun add(num1:Int,num2:Int):Int{<br>  return num1 + num2<br>}</pre><p>5. <strong>Properties</strong>: In Kotlin , you can define a property using the val (read-only) or var (read-write) keywords.</p><pre>fun main(){<br>  val name = &quot;Samuel&quot;<br>  var age = 5<br><br>  name = &quot;George&quot; // Not acceptable<br>  age = 6 // Acceptable<br><br>}</pre><p>While there are alot of features we can dive into I’ll stop there. Some of some interesting features you can look out for are extension functions, string interpolation, lambda expressions,operator overloading etc.</p><h3>Outputs</h3><p>In Kotlin outputs can be displayed using println() function.This function is used to print output to the standard output which is basically the console. Kotlin also supports the use of print() function which basically prints without adding a newline character to the end of the output.</p><pre>fun main(){<br>    val name = &quot;Hello World&quot;<br>    println(name)<br>}<br><br><br>fun main(){<br>  print(&quot;Hello &quot;)  <br>  print(&quot;World&quot;) // Hello World will be printed to the console without line break<br><br>}</pre><h3>Comments</h3><p>Comments help to provide explanations, documentation, or notes to yourself or other developers.In kotlin comments can either be single line or multiline.</p><p>Single line comments start with//and then continue until the end of the line.They are used to give brief explanation of the code.</p><pre>fun main(){<br>  // This is a single-line comment<br>  val age = 25<br>}</pre><p>Multi-line comments begin with /* and end with */. They are used for longer explanations, documentation, or commenting out multiple lines of code.</p><pre>fun main(){<br> /*<br>   This is a multi-line comment.<br>   You can write multiple lines of text here.<br>   It is often used for documenting functions, classes, or code blocks.<br>*/<br> val x = 10<br>}</pre><h3>Variables</h3><p>Variables in Kotlin provide us with various types of variable the common ones including mutable and immutable variables.</p><p>Mutable variables are declared using var keywords. These variables can be reassigned or modified after the initial assignment</p><pre>fun main(){<br>  var count = 10<br>  count = 20 //This is valid since count is a mutable variable<br>}</pre><p>Immutable variables are declared using the val keyword. Unlike the mutable variables they cannot be reassinged after the initial assignment.</p><pre>fun main(){<br>  val pi = 3.14159<br>  //pi = 3.14 // Error! Reassignment of a val is not allowed.<br>}</pre><p>Thats all for this article, I hope you enjoyed it. Keep coding in Kotlin and let your imagination soar!” 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d456ec5feff" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>