Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realm with Swift 2.1 project won't build when importing RealmSwift (module file was created by an older version of the compiler)

I'm on the very latest Xcode 7.1 and my project uses Swift 2.1. I followed all the directions on the Swift website for getting started (Dynamic Framework tab) and everything builds just fine until I try to import RealmSwift in my class. The compiler throws the following error on the line I try to import RealmSwift:

error: module file was created by an older version of the compiler; rebuild 'RealmSwift' and try again: /Users/USERNAME/Desktop/iosDev/PROJECTNAME/RealmSwift.framework/Modules/RealmSwift.swiftmodule/x86_64.swiftmodule

All the files are in the ${PROJECT_DIR} root (RealmSwift.framework and Realm.framework).

I have searched and searched for an answer, updated Xcode, deleted and reconfigured the library. I'm not sure what it means by 'rebuild RealmSwift' (I'm new to swift). The error only throws when I try to use the library in my class or use the Xcode plugin to create a new Realm Model Object.

like image 379
ItsPronounced Avatar asked Oct 23 '15 20:10

ItsPronounced


3 Answers

Realm Swift 0.96.2 was released on October 26 2015, adding support for Xcode 7.1 and Swift 2.1 This should address the issue you were seeing. Releases of Realm prior to 0.96.2 were built with Xcode 7 and supported Swift 2.0.

like image 122
bdash Avatar answered Oct 31 '22 20:10

bdash


I am also using Realm in the latest version of Swift, but instead of the Dynamic Framework method, I use the Cocoapods version of the installation.

This works for me.

But anyway, this of course doesn't solve your problem :).

Most of the time this error can be solved by just cleaning your project. In the Xcode menu, Select Product and then Clean. I had this same error with some SQLite libraries I was using and this fixed it most of the time.

like image 33
Wim Haanstra Avatar answered Oct 31 '22 19:10

Wim Haanstra


  1. Clone the repo or download as a Zip file and open: https://github.com/realm/realm-cocoa

  2. Open up a terminal window (mac) or some comparable alternative.

  3. On mac, you'd change to the directory of the repo via. cd ~/Path/To/The/Repo command in the terminal window. cd stands for change directory.
  4. Then, run this command: REALM_SWIFT_VERSION=2.1 sh build.sh build which will cause the project to be updated to Swift 2.1

  5. Then, you'll be able to drag the frameworks back into your Project.

REALM_SWIFT_VERSION - Change with your build Version of Swift (hear latest Version of Swift is 2.1).

This Take Some Minutes to Build with Your Specific Version.

like image 29
Ravi Mavani Avatar answered Oct 31 '22 21:10

Ravi Mavani