How to resolve the conflict between RealmSwift.App and SwiftUI.App in SwiftUI after iOS 14.0?

Viewed 314

I can not use App directly, nor can use RealmSwift.App. What can I do to resolve the conflict?

enter image description here

enter image description here

import SwiftUI
import RealmSwift

let app = RealmSwift.App(id: "tasktracker-qczfq")
@main
struct LandManagementApp: SwiftUI.App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Error:Module 'RealmSwift' has no member named 'App'

import SwiftUI
import RealmSwift

let app = App(id: "tasktracker-qczfq")
@main
struct LandManagementApp: SwiftUI.App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Error:Argument passed to call that takes no arguments Error:Protocol type 'App' cannot be instantiated

I installed Realm with swift manager package and did not change any build settings.

2 Answers

You can try the following:

import Realm
import SwiftUI

let app = RLMApp(id: "tasktracker-qczfq")

@main
struct LandManagementApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Using RLMApp in Swift code is an anti-pattern as it is a type from the Obj-C api. The way to distinguish between both App types would be to either prefix the namespace e.g. RealmSwift.App or add a typealias to help clear up some of the verbosity of qualifying each type.

e.g. typealias RealmApp = RealmSwift.App typealias SwiftApp = SwiftUI.App

Related