Search code examples
swiftrealmcarthageswift5

Cannot find interface declaration for 'RealmSwiftObject', superclass of


I had been using Swift 5 on Mojave 10.4.3 for a few weeks without a problem. Suddenly one of my projects stopped compiling with the error message in the title of this question. After searching and experimenting I found a solution to the issue, and am answering my own question. This problem is particularly heinous (i.e.: you can spend a lot of time going down blind alleys) since it didn't occur in other projects which are successfully using the Frameworks compiled using Carthage 0.32


Solution

  • I was using Carthage 0.32 to create the Realm and RealmSwift frameworks. After searching I was able to find a solution that worked for me. (RealmCocoa Issue 3073) Thanks to jweg29 at github for the solution.

    EDIT: See comment below from Larme. One should use Carthage 0.33 or above for Swift 5.

    I am posting the answer here since it is not obvious that the error is due to an outdated (only slightly) version of carthage.

    In the terminal, type:

    brew upgrade carthage
    

    cd to the directory containing your Cartfile file, and rebuild. For me this meant typing:

    carthage update --platform ios
    

    Replace the existing Realm and RealmSwift frameworks in your projects with the freshly created ones, clean (I used Shift-Option-Command-K to be sure) and you should be able to rebuild your project.