<?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 Ľuboš Lehota on Medium]]></title>
        <description><![CDATA[Stories by Ľuboš Lehota on Medium]]></description>
        <link>https://medium.com/@luboslehota?source=rss-a6e17efa20e2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Vh-RJ_FzvjDJUZSpHFpFUA.jpeg</url>
            <title>Stories by Ľuboš Lehota on Medium</title>
            <link>https://medium.com/@luboslehota?source=rss-a6e17efa20e2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 21:49:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@luboslehota/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[Adding Firestore to Your Kotlin Multiplatform Project: A Step-by-Step Guide]]></title>
            <link>https://luboslehota.medium.com/adding-firestore-to-your-kotlin-multiplatform-project-a-step-by-step-guide-f6669c42933f?source=rss-a6e17efa20e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6669c42933f</guid>
            <category><![CDATA[firestore]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kmm]]></category>
            <dc:creator><![CDATA[Ľuboš Lehota]]></dc:creator>
            <pubDate>Sun, 13 Apr 2025 09:41:32 GMT</pubDate>
            <atom:updated>2025-04-13T09:41:32.468Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MCwBwuoLsquwqDck_dNtcw.jpeg" /></figure><p>As an iOS developer dipping my toes into <strong>Kotlin Multiplatform (KMM)</strong>, I recently tackled integrating <strong>Google Firestore</strong> into a fun side project. While KMM promises shared code across platforms, setting up a real-time database like Firestore comes with its own set of challenges — especially if Gradle and multiplatform libraries feel like uncharted territory. After some trial and error (and a few Gradle-induced headaches), I’ve distilled the process into a clear, actionable guide, since I could not find the one up-to-date. Here’s how you can add Firestore to your KMM project, with practical tips to save you time and frustration.</p><p>— -</p><p>Firestore is a lightweight, real-time database that’s perfect for apps needing instant data sync across platforms. Pairing it with KMM lets you share business logic, however, Google’s lack of native KMM support means you’ll need to handle platform-specific initialization. Let’s break it down step-by-step.</p><p>— -</p><h4>Step 1: Set Up Your Google Project</h4><p>First, head to the <a href="https://console.cloud.google.com/">Google Cloud Console</a> and create a new project. Add your iOS and Android apps using their respective identifiers:</p><p>- <strong>iOS</strong>: Use the bundle identifier from your `Info.plist` (e.g., `com.example.app`).</p><p>- <strong>Android</strong>: Grab the `applicationId` from your `androidApp/build.gradle.kts`.</p><p>Download the configuration files:</p><p>- `<strong>GoogleService-Info.plist</strong>` for iOS.</p><p>- `<strong>google-services.json</strong>` for Android.</p><p>Enable Firestore in the console, and you’re ready for the next step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dnmaDTC0Wn4QfIqoiI1isw.jpeg" /></figure><h4>Step 2: Create Your Firestore Database</h4><p>In the Firestore dashboard, set up your database structure. For example, to store notes:</p><p>1. Click <strong>Start Collection</strong> and name it `notes`.</p><p>2. Add a document with fields like `title` (String) and `text` (String).</p><p>3. Use <strong>Auto-ID</strong> to generate a unique document ID.</p><p>This creates a simple structure to test with later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*35SDHi6jVKLT9ChJBkglxA.png" /><figcaption>Example of how your database could look like</figcaption></figure><h4>Step 3: Add Configuration Files to Your Project</h4><p>Place the configuration files in the right spots:</p><p>- <strong>iOS</strong>: Add `GoogleService-Info.plist` to the root of your iOS native project.</p><p>- <strong>Android</strong>: Place `google-services.json` in the `androidApp` directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*--l5Dg0kf8MV4YuvzukcZA.png" /><figcaption>Simplified visual project structure representation for better understanding</figcaption></figure><h4>Step 4: Configure Gradle for Firestore</h4><p>KMM projects have multiple `build.gradle.kts` files, which can be confusing. Here’s what each does and how to update them:</p><p>- <strong>Root </strong>`<strong>build.gradle.kts`</strong> (project-level):</p><p>Add the Google services plugin to enable Firestore tooling.</p><pre>buildscript {<br>  dependencies {<br>    classpath(libs.google.services)<br>  }<br>}</pre><p>- <strong>Shared </strong>`<strong>build.gradle.kts`</strong> (multiplatform level):</p><p>Add Firestore dependencies for shared and platform-specific code.</p><pre>...<br><br>sourceSets {<br>  commonMain.dependencies {<br>    ...<br>    implementation(libs.firebase.firestore)<br>  }<br>  androidMain.dependencies {<br>    ...<br>    implementation(libs.firebase.firestore.ktx)<br>  }<br>  iosMain.dependencies {<br>    ...<br>    implementation(libs.firebase.firestore)<br>  }<br>}</pre><p>Note: Since Google doesn’t provide a KMM-specific Firestore library, you’ll handle iOS initialization natively (more on this later). You may opt-in for using CocoaPods instead (not covered in this article).</p><p>- <strong>Android </strong>`<strong>build.gradle.kts`</strong> (`android app level`):</p><p>Apply the Google services plugin to link with `google-services.json`.</p><pre>plugins {<br>  id(&quot;com.google.gms.google-services&quot;)<br>}</pre><h4>Step 5: Initialize Firestore</h4><p>Create a shared `FirebaseInitializer` to handle Firestore setup across platforms. Here’s how:</p><p>- <strong>Common code</strong> (`shared/commonMain`):</p><p>Define an `expect` object to declare the initialization contract.</p><pre>import dev.gitlive.firebase.firestore.FirebaseFirestore<br><br>expect object FirebaseInitializer {<br>  fun initialize(context: Any?)<br>  val firestore: FirebaseFirestore<br>}</pre><p>- <strong>Android implementation</strong> (`shared/androidMain`):</p><p>Initialize Firebase with the Android context.</p><pre>import android.content.Context<br>import dev.gitlive.firebase.Firebase<br>import dev.gitlive.firebase.firestore.FirebaseFirestore<br>import dev.gitlive.firebase.firestore.firestore<br><br>actual object FirebaseInitializer {<br>  actual fun initialize(context: Any?) {<br>    Firebase.initialize(context = context as? Context)<br>  }<br><br>  actual val firestore: FirebaseFirestore<br>    get() = Firebase.firestore<br>}</pre><p>- <strong>iOS implementation</strong> (`shared/iosMain`):</p><p>Leave initialization empty for now (we’ll handle it natively unless using CocoaPods).</p><pre>import dev.gitlive.firebase.Firebase<br>import dev.gitlive.firebase.firestore.FirebaseFirestore<br>import dev.gitlive.firebase.firestore.firestore<br><br>actual object FirebaseInitializer {<br>  actual fun initialize(context: Any?) {<br>    // Empty for SPM; initialize natively<br>    // NOTE: Only works when using cocoapods with respective import here<br>    // Firebase.initialize()<br>  }<br><br>  actual val firestore: FirebaseFirestore<br>    get() = Firebase.firestore<br>}</pre><h4>Step 6: Platform-Specific Initialization</h4><p>- <strong>Android:</strong></p><p>Update `MainActivity` to call the initializer.</p><pre>class MainActivity : ComponentActivity() {<br>  override fun onCreate(savedInstanceState: Bundle?) {<br>    super.onCreate(savedInstanceState)<br>    FirebaseInitializer.initialize(this)<br>    <br>    ...<br>    <br>    setContent { /* Your UI */ }<br>  }<br>}</pre><p>- <strong>iOS</strong> (using Swift Package Manager):</p><p>Add the Firebase iOS SDK via SPM - <a href="https://github.com/firebase/firebase-ios-sdk.git">https://github.com/firebase/firebase-ios-sdk.git</a>. Then, initialize Firebase in your app’s entry point.</p><pre>import FirebaseCore<br>import SwiftUI<br><br>@main<br>struct iOSApp: App {<br>  var body: some Scene {<br>    WindowGroup {<br>      MainScreen()<br>        .onAppear {<br>          FirebaseApp.configure()<br>         }<br>      }<br>  }<br>}</pre><h4>Step 7: Pull Data from Firestore</h4><p>To fetch data, use Kotlin Serialization for easy model mapping. Add it to your shared Gradle:</p><pre>sourceSets {<br>  commonMain.dependencies {<br>    ...<br>    implementation(libs.kotlinx.serialization.json)<br>  }<br>}</pre><p>Create a `Note` model in `shared/commonMain`:</p><pre>import kotlinx.serialization.Serializable<br><br>@Serializable<br>data class Note(<br>  val id: String,<br>  val title: String,<br>  val text: String<br>)</pre><p>Then, add a `FirestoreWrapper` to load data in generic fashion:</p><pre>import kotlinx.serialization.Serializable<br><br>object FirestoreWrapper {<br>  suspend inline fun &lt;reified T : @Serializable Any&gt; loadDocuments(collectionPath: String): List&lt;T&gt; {<br>    val firestore = FirebaseInitializer.firestore<br>    return firestore<br>      .collection(collectionPath)<br>      .get()<br>      .documents<br>      .map { it.data&lt;T&gt;() }<br>  }<br>}</pre><p>Use it in a coroutine to fetch notes:</p><pre>launch {<br>  try {<br>    val notes = FirestoreWrapper.loadDocuments&lt;Note&gt;(&quot;notes&quot;)<br>    // Update state and propagate the change to UI<br>  } catch (e: Exception) {<br>    // Handle errors<br>  }<br>}</pre><p>— -</p><h4>Common Pitfalls and Fixes</h4><p>Here are some issues I ran into and how to resolve them:</p><p>- <strong>Firebase Initialization Errors</strong>:</p><ul><li>Double-check your `GoogleService-Info.plist` and `google-services.json` for correct IDs.</li><li>Ensure the `com.google.gms.google-services` plugin is applied in `androidApp/build.gradle.kts`.</li></ul><p>- <strong>Emulator Internet Issues</strong>:</p><ul><li>Add internet permission to your AndroidManifest.</li></ul><pre>&lt;uses-permission android:name=”android.permission.INTERNET” /&gt;</pre><ul><li>Set your emulator’s Wi-Fi DNS to <strong>8.8.8.8</strong>.</li></ul><p>— -</p><h4>Final Thoughts</h4><p>Adding Firestore to a KMM project isn’t plug-and-play, but it’s manageable with the right steps. The key is understanding Gradle’s role, handling platform-specific initialization, and leveraging libraries like Kotlin Serialization for clean data handling. While KMM has a learning curve, the ability to share logic across iOS and Android is worth the effort.</p><p>Have you tried Firestore with KMM? What challenges did you face? Drop a comment — I’d love to hear your tips or answer any questions!</p><p><strong>#KotlinMultiplatform #Firestore #MobileDevelopment #iOS #Android</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6669c42933f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s Isolate SwiftData for Cleaner Architecture]]></title>
            <link>https://luboslehota.medium.com/lets-isolate-swiftdata-for-cleaner-architecture-d8f87116bf27?source=rss-a6e17efa20e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8f87116bf27</guid>
            <category><![CDATA[swiftdata]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Ľuboš Lehota]]></dc:creator>
            <pubDate>Tue, 25 Mar 2025 13:16:24 GMT</pubDate>
            <atom:updated>2025-03-25T13:16:24.346Z</atom:updated>
            <content:encoded><![CDATA[<p>The <strong>SwiftUI</strong> world sometimes suffers from the same issues that <strong>UIKit</strong> did in the past.</p><p>Let’s take a look at a basic <strong>SwiftData</strong> example generated by <strong>Xcode</strong>.</p><pre>@main<br>struct SwiftDataExampleApp: App {<br>  var sharedModelContainer: ModelContainer = {<br>    let schema = Schema([<br>      Item.self,<br>    ])<br>    let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)<br><br>    do {<br>      return try ModelContainer(for: schema, configurations: [modelConfiguration])<br>    } catch {<br>      fatalError(&quot;Could not create ModelContainer: \(error)&quot;)<br>    }<br>  }()<br><br>  var body: some Scene {<br>    WindowGroup {<br>      ContentView()<br>    }<br>    .modelContainer(sharedModelContainer)<br>  }<br>}<br><br>struct ContentView: View {<br>  @Query private var items: [Item]<br>  @Environment(\.modelContext) private var modelContext<br> <br>  ...<br>  <br>  private func addItem() {<br>    let newItem = Item(timestamp: Date())<br>    modelContext.insert(newItem)<br>    try? modelContext.save()<br>  }<br>}</pre><p>There are several issues with this approach:</p><ul><li><strong>Tightly Coupled Logic and View — </strong>The logic is embedded directly within the view, making it difficult to reuse without also reusing the view itself.</li><li><strong>View-Specific Property Wrappers (</strong><strong>@Environment, </strong><strong>@Query) — </strong>These property wrappers are designed to work <strong>only inside SwiftUI views</strong>. They automatically update the UI when data changes but restrict how we handle data outside the view.</li><li><strong>Binding The Context to the View Hierarchy — </strong>The .modelContainer(sharedModelContainer) function passes down the model context, making all logic dependent on the environment’s container. This prevents the use of <strong>separate containers</strong>, as @Query is tightly coupled to the passed environment.</li></ul><h4>DECOUPLING THE LOGIC</h4><p>Let’s assume we don’t want separate containers but still need to <strong>decouple model operations from the view</strong>. Since modelContext is an environment property, it <strong>must be used within a view</strong>, making it impossible to pass the context into a dedicated data manager at initialization.</p><p>One possible solution we could think of could be to create another instance of ModelContext:</p><pre>@main<br>struct SwiftDataExampleApp: App {<br>  var body: some Scene {<br>    WindowGroup {<br>    ContentView()<br>  }<br>  .modelContainer(AppModelContainer.shared)<br>}<br><br>enum AppModelContainer {<br>  static let shared: ModelContainer = {<br>   ...<br>  }()<br>}<br><br>class ContentViewModel {<br>  let modelContext: ModelContext = .init(AppModelContainer.shared)<br><br>  func addItem() {<br>    let newItem = Item(timestamp: Date())<br>    modelContext.insert(newItem)<br>    try? modelContext.save()<br>  }<br>}</pre><p>Well, this is obviously not working since those two ModelContext instances are not the same. So the changes from one context do not affect the second context.</p><p>To fix this, we have to make some shared instance of the ModelContext instead.</p><pre>@main<br>struct SwiftDataExampleApp: App {<br>   var body: some Scene {<br>     WindowGroup {<br>       ContentViewImproved()<br>     }<br>     .modelContext(AppModelContainerProvider.context)<br>   }<br>}<br><br>enum AppModelContainerProvider {<br>  private static let modelContainer: ModelContainer = {<br>    ...<br>  }()<br><br>  static let context: ModelContext = {<br>    return ModelContext(modelContainer)<br>  }()<br>}<br><br>class ContentViewModel {<br>  let modelContext: ModelContext = AppModelContainerProvider.context<br><br>  func addItem() {<br>    let newItem = Item(timestamp: Date())<br>    modelContext.insert(newItem)<br>    try? modelContext.save()<br>  }<br>}<br><br>struct ContentView: View {<br>  @Environment(\.modelContext) private var modelContext<br>  private let viewModel = ContentViewModel()<br>    <br>  ...<br>}</pre><p>Now, let’s say we want to <strong>delete items</strong>. In the view, the function might look like this:</p><pre>func deleteItems(offsets: IndexSet) {<br>  for index in offsets {<br>    modelContext.delete(items[index])<br>    try? modelContext.save()<br>  }<br>}</pre><p>However, moving this logic to ContentViewModel introduces a problem: <strong>ModelContext doesn’t provide a direct way to delete items by index</strong>. We need to first fetch the items and then delete the corresponding instances:</p><pre>class ContentViewModel {<br>  private let modelContext: ModelContext = AppModelContainerProvider.context<br><br>  func addItem() {<br>    let newItem = Item(timestamp: Date())<br>    modelContext.insert(newItem)<br>    try? modelContext.save()<br>  }<br><br>  func deleteItems(offsets: IndexSet) {<br>    guard let items = try? modelContext.fetch(FetchDescriptor&lt;Item&gt;()) else { return }<br><br>    for index in offsets {<br>      modelContext.delete(items[index])<br>      try? modelContext.save()<br>    }<br>  }<br>}</pre><h4>Observing changes</h4><p>What if we want to <strong>apply custom logic when data changes</strong>? To do this, we need to observe changes and notify ContentViewModel.</p><p>A possible approach is to use<strong> </strong><strong>@Query </strong>inside the view and notify our<strong> </strong>ContentViewModel<strong> </strong>when data changes:</p><pre>struct ContentView: View {<br>  @Query private var items: [Item]<br>  @StateObject var viewModel: ContentViewModel = .init()<br><br>  var body: some View {<br>    ListView {<br>    ...<br>    }<br>    .onAppear {<br>      viewModel.fetch()<br>     }<br>    .onChange(of: items) {<br>      viewModel.fetch()<br>    }<br>  }<br>}<br><br>class ContentViewModel: ObservableObject {<br>  @Published var items: [Item] = []<br>  private let modelContext: ModelContext = AppModelContainerProvider.context<br> <br>  func addItem() {<br>   ...<br>  }<br><br>  func deleteItems(offsets: IndexSet) {<br>   ...<br>  }<br><br>  func fetch() {<br>    items = (try? modelContext.fetch(FetchDescriptor&lt;Item&gt;())) ?? []<br>    <br>    // DO SOME DESIRED MUTATIONS HERE<br>    ...<br>  }<br>}</pre><p>While this approach works, <strong>it still relies on </strong><strong>@Query</strong>. To fully decouple the view model from the view, we can <strong>observe changes using NotificationCenter</strong>:</p><pre>struct ContentViewModelState {<br>  var items: [Item] = []<br>}<br><br>class ContentViewModel: ObservableObject {<br>  @Published var state: ContentViewModelState = .init()<br>  private let modelContext: ModelContext = AppModelContainerProvider.context<br>  private var observations: [Task&lt;Void, Never&gt;] = []<br><br>  func addItem() {<br>    ...<br>  }<br><br>  func deleteItems(offsets: IndexSet) {<br>    ...<br>  }<br><br>  func fetch() {<br>    ...<br>  }<br><br>  func observeRecordChanges() {<br>    let task = Task {<br>      let stream = NotificationCenter.default.notifications(named: ModelContext.didSave)<br> <br>      for await _ in stream {<br>        await MainActor.run {<br>         fetch()<br>        }<br>      }<br>    }<br>   <br>    observations.append(task)<br>  }<br><br>  func cancelTasks() {<br>   observations.forEach {<br>     $0.cancel()<br>   }<br>   observations.removeAll()<br>  }<br>}<br><br>struct ContentView: View {<br>  @StateObject var viewModel: ContentViewModel = .init()<br>  var body: some View {<br>    ...<br>    .onAppear {<br>      viewModel.fetch()<br>      viewModel.observeRecordChanges()<br>    }<br>    .onDisappear {<br>      viewModel.cancelTasks()<br>    }<br>  }<br>}</pre><p>By making these improvements:</p><ul><li><strong>We can now observe changes globally</strong> and react accordingly, instead of being tied to the view.</li><li><strong>The model context is accessed directly</strong>, eliminating the need to pass it through the hierarchy.</li><li><strong>Data can be prepared before the view appears</strong>, ensuring a seamless user experience.</li><li><strong>Logic is separated into distinct entities</strong>, improving maintainability and scalability.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8f87116bf27" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ADDING TESTS TO PROJECT WITH MODULAR ARCHITECTURE]]></title>
            <link>https://luboslehota.medium.com/adding-tests-to-project-with-modular-architecture-6c999b8bfb9c?source=rss-a6e17efa20e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c999b8bfb9c</guid>
            <category><![CDATA[modular-architecture]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Ľuboš Lehota]]></dc:creator>
            <pubDate>Wed, 17 Mar 2021 16:28:28 GMT</pubDate>
            <atom:updated>2021-03-17T16:28:28.878Z</atom:updated>
            <content:encoded><![CDATA[<p>In my company, we tend to use modular architecture. We separate features in separate projects and have them all open in one workspace. This brings some joys, but on the other hand, it also brings some problems. For instance with adding tests.</p><p>As I haven’t found any complex answer for that, I wrote down an easy step-by-step tutorial, which some of you may find useful.</p><h3><strong>OUR PROJECT STRUCTURE</strong></h3><p>Since it’s always easier to imagine on direct example, imagine a scenario described in <strong>Img. 1</strong>. We have one workspace which contains three projects. One for Pods, one for the main app called MyProject with product name MyApp and an embedded framework product from the second project called MyFramework. MyFramework project has two targets, one for the framework itself, another one for tests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7YxfkWuCbuxbposOFDPb7Q.png" /><figcaption><strong>Img. 1</strong>: Our project structure</figcaption></figure><h3><strong>ADDING TEST TARGET</strong></h3><p>Now imagine a scenario, a test target is not yet added. First tap on the project for which you want to create the test target. Then tap on the little plus icon marked in red in <strong>Img. 2</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4mj_vsoAHNigjqdeUvQ4uQ.png" /><figcaption><strong>Img. 2</strong>: Adding new target</figcaption></figure><p>Now, under the Test section, you will find Unit Testing Bundle(<strong>Img. 3</strong>). Fill in mandatory information and you will end up with something looking like in <strong>Img. 4</strong>. Notice how it has no hosting app. And that is the root of the problem. You need a hosting app on which the tests are being executed. Check the dropdown and you will see there are no options. Luckily that is just another peril from Apple, which is easily defeated as in the following step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3cn8LBdF6I3FaX_R8bfjKA.png" /><figcaption><strong>Img. 3</strong>: New target type</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rZdeK0lsAVnenoX2t3USxw.png" /><figcaption><strong>Img. 4</strong>: Result after Test bundle has been added</figcaption></figure><h3><strong>ADDING HOST APP FOR TESTS</strong></h3><p>Below stated Stackoverflow thread helped me a lot with running tests under my app executable.</p><p><a href="https://stackoverflow.com/questions/41940072/cant-run-tests-in-a-xcode-project-that-imports-another-framework">Can&#39;t run tests in a Xcode project that imports another framework</a></p><p>Open your test target and navigate to Build Settings. Search for Test Host(<strong>Img. 5</strong>) and add a value for it in the following form:</p><pre><strong>$(BUILT_PRODUCTS_DIR)/{YOUR PRODUCT NAME}.app/{YOUR PRODUCT NAME}</strong></pre><p>So in my case, it is:</p><pre><strong>$(BUILT_PRODUCTS_DIR)/MyApp.app/MyApp</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GgfhkrS9k31LUOwsDuinjQ.png" /><figcaption><strong>Img. 5</strong>: Setting host</figcaption></figure><p>But our work is not done yet. As it is stated in the accepted answer for the thread, you also need to specify from where the bundle for executable will be loaded. Just search for another term Bundle Loader still under test target build settings and set it to</p><p><strong>$(TEST_HOST)</strong></p><p>as shown in <strong>Img. 6.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0x5eZjVYbuu77274ynbP-g.png" /><figcaption><strong>Img. 6</strong>: Setting the bundle of the host app</figcaption></figure><h3><strong>TELLING THE APP TO RUN YOUR FRAMEWORK TESTS</strong></h3><p>Now, this is the easiest part. Just edit your app scheme. Under the Test tab and then Info tab, tap plus sign (<strong>Img. 7</strong>). And then lookup for your test target in the list (<strong>Img. 8</strong>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VVFcQ4OXiPnx4v66SmnKsA.png" /><figcaption><strong>Img. 7</strong>: Linking your tests to your app scheme</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4-SdhIQHAYM6t2EKoU1Uyg.png" /><figcaption><strong>Img. 8</strong>: Adding test target to hosting app</figcaption></figure><p>Now you are all set, you can run tests using <strong>CMD+U</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z4UhxNdL-S4WcFRV6aMVpQ.png" /><figcaption><strong>Img. 9</strong>: Successfully executed default tests</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c999b8bfb9c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>