<?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 Mehdi Sohrabi on Medium]]></title>
        <description><![CDATA[Stories by Mehdi Sohrabi on Medium]]></description>
        <link>https://medium.com/@mehdok?source=rss-22e6c8531bdf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*VF7Z6Sz3kxCuQVig.</url>
            <title>Stories by Mehdi Sohrabi on Medium</title>
            <link>https://medium.com/@mehdok?source=rss-22e6c8531bdf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 21:03:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mehdok/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[MVVM, How we used it, How it helped us]]></title>
            <link>https://medium.com/rekab/mvvm-how-we-used-it-how-it-helped-us-dc9a7d4bf4d?source=rss-22e6c8531bdf------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc9a7d4bf4d</guid>
            <category><![CDATA[rxswift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[mvvm]]></category>
            <dc:creator><![CDATA[Mehdi Sohrabi]]></dc:creator>
            <pubDate>Tue, 16 Apr 2019 14:33:01 GMT</pubDate>
            <atom:updated>2019-04-16T14:33:01.702Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*iSqgmNvSUzlWVNWciBnwDg.jpeg" /></figure><p>The name of <strong>MVVM</strong> is so cool that you may think it is a super architecture model that eases everything from coding to debugging. But, does it actually do all of that? Based on our experience in REKAB, the answer is a big no.</p><p>MVVM alone won’t do that for you, but if you combine it with some other methods like binding with <strong>Rx</strong> and using <strong>Coordinator</strong>, then you can claim that MVVM eases everything.</p><blockquote>Ease-up coding doesn’t mean less code. It means cleaner code to write and read. Using MVVM + Rx Binding + Coordinator leads to even more lines of code. This is what happened with REKAB when we start using this technique and our code became larger by 20 to 30 percent, but a few lines of code doesn’t bother anyone as long as it makes debugging easier and adding new feature simpler.</blockquote><p>There are so many tutorials on MVVM + Coordinator and using Rx concept and I don’t want to repeat them here. What I want to discuss is how we use these techniques and how it helped us to make REKAB development better, faster and less buggy.</p><h3>Bind, Bind, Bind</h3><p>MVVM is based on binding and there are 2 methods for binding, The cool way and the other way. The cool way uses Rx for binding which is more robust and you can bind almost everything. The other way employs Swift didSet. You can call a function or do something when a value didSet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67a79c0914696f45e73a24389294397a/href">https://medium.com/media/67a79c0914696f45e73a24389294397a/href</a></iframe><p>I’m not considering this as a binding method. Actually I’m not even sure binding is possible without using Rx.</p><p><a href="https://github.com/ReactiveX/RxSwift">RxSwift</a> and <a href="https://github.com/ReactiveX/RxSwift/tree/master/RxCocoa">RxCocoa</a> will cover most of the binding job for you. There is other Rx based library form Rx Community like <a href="https://github.com/RxSwiftCommunity/RxDataSources">RxDataSources</a> and <a href="https://github.com/RxSwiftCommunity/RxGesture">RxGesture</a> that can help you do more binding. Using these libraries are easy but I show some examples here. (For more examples you can check out our <a href="https://github.com/rekab-app/MVVMCExample">GitHub</a>)</p><p>You can bind button click:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f9ab56c2d80a3a5073507db75d19df9/href">https://medium.com/media/6f9ab56c2d80a3a5073507db75d19df9/href</a></iframe><p>You can use BehaviorRelay to store value and take action when it did set:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ae7de0cfee5aca4a26f89e97cb9915b/href">https://medium.com/media/9ae7de0cfee5aca4a26f89e97cb9915b/href</a></iframe><p>If you want to bind to some custom method you can do it this way:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/469139e2e44eebf16c145cb10978b39c/href">https://medium.com/media/469139e2e44eebf16c145cb10978b39c/href</a></iframe><blockquote>Remember to <strong>dispose</strong> every bind you have created. Every binding creates a subscription that will exist as long as app exists, not disposing these can cause major problems like memory leak or unexpected behavior.</blockquote><h3>Coordinator</h3><p>So you are using MVVM + Rx Binding but something is missing here, you need a way of communication between different parts of your app. You need to send initial parameter to viewController or viewModel and even get the results back. Well, we can use our old friend delegate. But why not using some better solution? With the help of coordinator you can create an isolate module that has inputs and outputs.</p><p>This is a great news for us, we can create an isolate module that is immune from changes in other modules, this means less bugs, less debug time, reusability, and lowering costs. This is all we want. Isn’t it?</p><p>The Coordinator is like glue and bridge, it is responsible for creating UseCase for viewModel, creating and connecting viewController, set initial parameter and sending back results, here is a glimpse: (you can find full example at <a href="https://github.com/rekab-app/MVVMCExample">GitHub</a>)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f28475ef6e79a97695e3bdca10f340e/href">https://medium.com/media/2f28475ef6e79a97695e3bdca10f340e/href</a></iframe><h3>Huge Storyboard</h3><p>As your project grows bigger and bigger your storyboard file gets bigger too. Finally when you click on storyboard you have to wait until it gets open. Scrolling is nightmare, segue connection is everywhere, any change in a button text can take several seconds to update and so on.</p><p>We overcame this issue by separating storyboard for each ViewController and also avoiding segue. All of the connections are handled by coordinator, so you don’t need to create any segue. You can also create a protocol to make your life easier with storyboard initialization:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32c31f664cb2977eb23e2f421ec4bad6/href">https://medium.com/media/32c31f664cb2977eb23e2f421ec4bad6/href</a></iframe><h3>Separate Framework</h3><p>This is completely optional (as the rest of the article), but you can make your code more organized by creating separate module for each part of the app. You can have a <strong>MainScreen</strong> module, <strong>Login</strong> module and etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*8LqmVjvJeAf9wtIP2jG8vw.png" /><figcaption>sample of app modules</figcaption></figure><p>The important thing to remember is how you organize the pod file. consider this example of our app:</p><p>We have <em>Profile</em> module that embedded into <em>MainScreen module, </em>and<em> MainScreen </em>module embedded into <em>REKAB</em> module, so if you use a pod in <em>Profile</em> module you have to include it in both MainScreen and <em>REKAB</em> module:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59cd75263c9a6547abd6035b3dbbc8ff/href">https://medium.com/media/59cd75263c9a6547abd6035b3dbbc8ff/href</a></iframe><p><a href="https://github.com/rekab-app/MVVMCExample">rekab-app/MVVMCExample</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc9a7d4bf4d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/rekab/mvvm-how-we-used-it-how-it-helped-us-dc9a7d4bf4d">MVVM, How we used it, How it helped us</a> was originally published in <a href="https://medium.com/rekab">rekab</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin Multiplatform]]></title>
            <link>https://medium.com/rekab/kotlin-multiplatform-2cde95ad79f?source=rss-22e6c8531bdf------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cde95ad79f</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ridesharing]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Mehdi Sohrabi]]></dc:creator>
            <pubDate>Mon, 18 Mar 2019 20:56:53 GMT</pubDate>
            <atom:updated>2019-03-18T20:56:53.427Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*s2d_y1ABDDI3rC-Bb5v-vg.jpeg" /></figure><p>It’s never been easy to develop a multi-platform mobile app that can do multiple tasks at the same time and serves many users simultaneously. You need to make sure it has least bugs or you will lose your users. On the other side, as the app gets bigger and bigger, your code becomes more complex and bug prone. So, what’s the solution?</p><p>REKAB is available for both iPhone and Android users and we are maintaining two sources codes (huge code base obviously). To control cost and quality, for some of our core modules, we are using Kotlin multi platform solution, to share code base between Android and iOS.</p><p>I am going to explain how we coded the Network Module in Kotlin and how we are using it.</p><h3><strong>Kotlin Shared Network Module</strong></h3><blockquote><strong>Before We begin</strong>, note that the library you use for every multi-platform module must have 3 versions: a core version, an Android version and a native (iOS) version. If any 3rd party library has this 3 versions, you can use it in your module without any problem.</blockquote><p>For networking, we use <a href="https://ktor.io/"><strong>ktor</strong></a>. But, you can use any library you wish as long as it is available for native networking.</p><p><strong>Project Setup</strong></p><p>For setting up your project and shared module you can follow Kotlin’s <a href="https://kotlinlang.org/docs/tutorials/native/mpp-ios-android.html">official guide</a>.</p><p>That is pretty straightforward expect the part on <a href="https://kotlinlang.org/docs/tutorials/native/mpp-ios-android.html#creating-the-shared-module"><strong>Creating The Shared Module</strong></a>, There is no such thing in Android Studio for creating pure Kotlin module, so you can create a java module, remove all the Gradle configs and delete the default java class, so you can use it as a Kotlin module.</p><p>The <a href="https://kotlinlang.org/docs/tutorials/native/mpp-ios-android.html">tutorial</a> suggests one way to export the result module as an iOS framework. The output Framework is cpu based, so if you want to run the app on simulator you have to create `x86` Framework and if you want to run the app on real device you have to create `arm64` Framework. I’ll use a way to make this build process automatic so you don’t need to do anything manually , you can read more about it in this <a href="https://medium.com/xebia-france/understanding-the-basics-of-multiplatform-projects-in-kotlin-1-3-1221689b3084">Article</a>.</p><p><strong>Threading</strong></p><p>As you know threading in Android and iOS is completely different. Threading is a system specific feature and you can not use one type of threading in both platforms. So, what can we do? We need to run our code to fetch json from server <strong>asynchronously</strong> in the background thread and deliver the result in the UI thread. The good news is that as a part of Multiplatform ecosystem there is a library for this propose, called <a href="https://github.com/Kotlin/kotlinx.coroutines">kotlinx.coroutines</a>.</p><p>Using this library is pretty straightforward, it employs the concept of Dispatchers.</p><p>I’ll use <em>Dispatchers.</em><strong><em>Main</em></strong> for the UI Thread, <em>Dispatchers.</em><strong><em>Default</em> </strong>for the Android background Thread and I’ll show you the iOS dispatcher in the fun part section.</p><p><strong>Jump into the code</strong></p><p>In this part you should follow the <a href="https://kotlinlang.org/docs/tutorials/native/mpp-ios-android.html">Kotlin’s official guide</a> to build a Multiplatform project and get the project ready.</p><p>The first thing we do is set up `Gradle` file for shared module. The final gradle file is something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d219a0894d59da5f5e77381e6bb2b770/href">https://medium.com/media/d219a0894d59da5f5e77381e6bb2b770/href</a></iframe><p>First we indicate that this is a Multiplatform module by putting the plugin at the beginning of the file:</p><pre>apply <strong>plugin</strong>: <strong>‘kotlin-multiplatform’</strong></pre><p>We are using data serialization for json so we have to add another plugin:</p><pre>apply <strong>plugin</strong>: <strong>‘kotlinx-serialization’</strong></pre><p>We also have 3 different sets of dependencies for each part, commonMain has the dependencies for common part of the code, respectively androidMain and iOSMain contains dependencies for Android and iOS.</p><blockquote>The sets are case sensitive, beware if you are getting any error.</blockquote><h3>The Fun Part</h3><p>After setting up the Gradle configs, we are going to create 3 different sets for 3 parts of our code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*nEcZM0Nt2PR48eeSQK8IWQ.png" /><figcaption>Sets configuration of Shared Module</figcaption></figure><p>The image is pretty straightforward, but as you may have noticed we have 3 main classes, the common will do most of the networking for us and we use the actual class to do platform specific codes.</p><p>The only platform specific thing is Threading, so we should provide different workers for different platforms. To accomplish this we used CoroutineDispatcher. In the common class we specify that we expect a dispatcher and each platform set is obligated to provide that for us.</p><pre><strong>internal expect val </strong><em>dispatcher</em>: CoroutineDispatcher</pre><blockquote>CoroutineDispatcher is great, The only downside is that it doesn’t currently support multithreading.</blockquote><p>So in the actual class of Android set we provide a dispatcher for Android:</p><pre><strong>internal actual val </strong><em>dispatcher</em>: CoroutineDispatcher = Dispatchers.<strong>Default</strong></pre><p>And in the iOS set we provide iOS specific dispatcher:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abad027dfa2ecee527164b8cd40e5980/href">https://medium.com/media/abad027dfa2ecee527164b8cd40e5980/href</a></iframe><p><strong>Thats all</strong>, . Now we can continue to write all of our network methods in common class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ce09c9929e524634984d832f71a60be/href">https://medium.com/media/1ce09c9929e524634984d832f71a60be/href</a></iframe><p>By following these simple steps we have a network library that works on both Android and iOS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*P_WBmjifU8YVtFFx7CScyw.jpeg" /><figcaption>Output on iOS and Android device</figcaption></figure><h3>Automatic Build of Framework</h3><p>As i mentioned before, The final Framework output is cpu based, But we want to make this process automatic so the platform automatically getting build for us. The steps to doing this is as follow:</p><ol><li>create a config for SharedModule to detect which cpu architecture we are using.</li></ol><p>2. Create a <strong>User Defined Setting</strong> in XCode to indicate cpu architecture.</p><p>3. Feed This parameter to Gradle script in runtime.</p><p>The Gradle config will search for parameter named Kotlin.device in input parameter and will decide to create x86 or arm64 Framework.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ccd270c66b7cb295221a5dbb6377869/href">https://medium.com/media/9ccd270c66b7cb295221a5dbb6377869/href</a></iframe><p>In XCode in <strong>Build Settings </strong>of your project you have to define a parameter like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2PnYk6-j6PH67hGNAXzI0A.png" /><figcaption>xcode specific parameter</figcaption></figure><p>You are just indicating a parameter to clarify which cpu architecture you are using.</p><p>and finally you have to update your <strong>Run Script </strong>to pass this parameter to the Gradle:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f20696c0bdb6c86b6bbd3f108a8eddca/href">https://medium.com/media/f20696c0bdb6c86b6bbd3f108a8eddca/href</a></iframe><ul><li><a href="https://github.com/rekab-app/KotlinSharedNetwork-android">rekab-app/KotlinSharedNetwork-android</a></li><li><a href="https://github.com/rekab-app/KotlinSharedNetwork-iOS">rekab-app/KotlinSharedNetwork-iOS</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cde95ad79f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/rekab/kotlin-multiplatform-2cde95ad79f">Kotlin Multiplatform</a> was originally published in <a href="https://medium.com/rekab">rekab</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>