Resolve the issue ‘App is ambiguous for type’ with Realm in your SwiftUI project
I recently realized that there is a problem while integrating realm into swift. The problem was caused by Dependency Name Collision. Let’s solve it in 3 seconds.
Dependency Name Collision Example
This is the problem I recently found. When you use Realm
, compilation error occurs with “‘App’ is ambiguous for type lookup in this context”.
The origin of the problem
This is because RealmSwift is using App
and clearly your SwiftUi app is also using App protocol. How do I resolve this issue?
Issue Solved
By specifying that you are importing App
from SwiftUI, this issue can be easily resolved!
Conclusion
- Realm uses
App
in its module and SwiftUI usesApp
in its module. It causes ambiguous type error. - Just by specifying you’re importing
App
from SwiftUI, this issue can go away for good in a second.