17

Swift 4.2 came out and I'm receiving this error message in my project when using ObjectMapper and some other pods too:

Module compiled with Swift 4.1.2 cannot be imported in Swift 4.1.50

So how do I tell Xcode to start updating my project and migrate it to Swift 4.2?

Sahil Kapoor
  • 11,183
  • 13
  • 64
  • 87

5 Answers5

26

You are not compiling your Carthage module with the proper swift version. So you need to:

  1. Make sure your terminal is pointing to your Xcode 10 Beta app and not your regular Xcode:

sudo xcode-select -switch Xcode_beta_10.app

  1. Update your Carthage files:

carthage update --platform iOS --no-use-binaries

  1. Go back to your project in Xcode, clean, build
Ed.
  • 3,923
  • 1
  • 15
  • 18
8

In Swift 4.2 there is a change in implementation of Implicitly Unwrapped Optional (IUO), as per the swift blog now implicit unwrapped optional T! will be considered as T? with and extra flag for the compiler to know it is an implicit unwrap optional.

The new mental model for IUOs is one where you consider ! to be a synonym for ? with the addition that it adds a flag on the declaration letting the compiler know that the declared value can be implicitly unwrapped.

Because of this change there might be some source compatibility issue that may requires you to modify your code before it will compile successfully.

In Swift 3, declarations like var a: Int? would result in a having type Optional, and declarations like var b: String! would result in b having type ImplicitlyUnwrappedOptional. It changed in Swift 4.2 hence its showing error for ObjectMapper for Xcode 10 which comes with swift 4.2 and similar implementation was done for 3.* for Xcode 10.

In Objectmapper library there are some declarations of functions which showed warnings earlier for swift 4.1, now showing as error for swift 4.2. Refer the below image for warnings in Xcode 9.4 and swift 4.1

enter image description here

There are some pull requests on the ObjectMapper GitHub repo which has fixed the issue but they are waiting for the new Xcode beta release as per the discussions as it is using complier directive feature which got recently accepted will be released with new Xcode beta.

Update: The issue is fix in ObjectMapper 3.3.0 version.

Suhit Patil
  • 11,748
  • 3
  • 50
  • 60
1

Run this below command in your project directory using the terminal. It will update your pod. Hope it will solve your problem.

pod update ObjectMapper
Sagar Unagar
  • 201
  • 1
  • 6
  • 18
0

You need to switch Xcode beta version in terminal.And remove old version Carthage document in your project. update carthage carthage update --platform iOS --no-use-binaries.

user3488542
  • 103
  • 10
-1

I had the same issue with Alamofire too.

My fix was

  1. clean up my build
  2. go to File/Workspace Settings and make sure you are using Legacy Build System for Build System. And then the issue's gone.
Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96
Lalaphoon
  • 349
  • 1
  • 4
  • 10
  • 2
    Didn't work for "import RealmSwift".. Module compiled with Swift 4.1.2 cannot be imported by the Swift 4.2 – Vito Valov Oct 25 '18 at 15:16