73

I have installed swift pods for the obj c project. I got this error when I was trying to build it.

enter image description here

I have gone through all the solutions like deleting derived data, cleaning the build folder. Swift Compiler_Language also missing in the XCode 10. Added user-defined setting too, even it didn't work.

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
Kumaraprasad
  • 733
  • 1
  • 5
  • 6
  • 1
    In case you got here after adding a Core Data model to an Objective-C project: https://stackoverflow.com/a/54763481/74118 – nevan king Feb 19 '19 at 10:03

9 Answers9

102

Select your app target then goto build setting, search for swift set the swift language version from the dropdown.

enter image description here

Ratul Sharker
  • 7,484
  • 4
  • 35
  • 44
  • 1
    There is no option of SWIFT COMPILER -LANGUAGE in Xcode 10. That is the issue. Is there any solution to fix? – Kumaraprasad Oct 24 '18 at 05:15
  • i thought you we're right and xcode 10 removed the `Swift Language Version` option, this only available to older version. So i created a new iOS Project but found the `Swift Language Version` in that project. Make sure you select the correct target and goto the `Build settings` tab and search for `swift lan` it will show up. – Ratul Sharker Oct 24 '18 at 05:25
  • It didn't work. I have created a new project and followed the rest of the procedure. Still, no options...:( – Kumaraprasad Oct 24 '18 at 05:48
  • Could you please share a screenshot what you get in `Build Setting` while opening a new project and searched for `swift lan`. Please share the exact xcode 10 version. – Ratul Sharker Oct 24 '18 at 05:53
  • Please check the attached screenshot. – Kumaraprasad Oct 24 '18 at 06:06
  • 3
    Select the mother project's target, not the `Pods` target. By mother project i mean the project which included this pods as dependency – Ratul Sharker Oct 24 '18 at 06:09
  • Yes. Working. Thank you so much.:) – Kumaraprasad Oct 24 '18 at 06:57
  • Strange, in a Flutter iOS project, the swift version is available in Pods target build settings for Xcode 10. – Vijay Kumar Kanta Nov 07 '18 at 02:16
34

In case there is anybody else reading through this thread who has this same problem but was unable to solve it using the above answers, this may help:

If you have a data model, you need to check that when you click on the data model, click on an entity, and bring up the file inspector, the "Code Generation" Language is properly set. In my case my whole app was written Objective-C, but was set here to Swift for some reason. This is another reason that Error will show up in the Issue Navigator.

It's very important to clear the build folder after changing Code Generation Language. This can be done by pressing Command-Shift-K or by clicking Product->Clean Build Folder in the menu at the top of the screen.

Check out this link for a picture of where to find the "Code Generation" option I'm talking about.

Model.xcdatamodeld->File Inspector->Code Generation

Io-oI
  • 2,514
  • 3
  • 22
  • 29
BMPatterson
  • 481
  • 4
  • 7
  • Thank you, @bmpatterson this was the answer for me :) – MGY Jul 11 '19 at 11:52
  • Perfect, thanks: This happened to me after adding a new model to Objective-C project, before even generating the code for entity objects. Lost hours. Glad I read down this far. – Henry95 Oct 07 '19 at 10:32
  • tyvm! This was the reason that I was having the build error! – sang Dec 31 '19 at 15:50
  • This is a proof Swift ruined Apple development joy and coherency. Swift introduction created tons of Xcode new problems, incoherencies, needed tweaks. Thanks for this one I would never have found this myself! – Altimac May 29 '20 at 12:12
  • Glad to see it's helped a few people! – BMPatterson Jul 07 '20 at 04:47
11

Update for Xcode 10.2

  1. Go to --> Build Setting

  2. Select All + Combined or All + Levels underneath the Build Settings

  3. And Finally on the search bar, on the right hand side search for "Swift Language Version"

as you see in the image worked for me

4

For a Cordova app add the following line in config.xml

<preference name="SwiftVersion" value="5.3"/>
Kent Bull
  • 1,144
  • 3
  • 21
  • 41
Navi
  • 41
  • 1
3

You need to search for every "PRODUCT_NAME =" There needs to be a " SWIFT_VERSION = "4.2"; " after everyone. eg. also PRODUCT_NAME = "$(TARGET_NAME)";enter code here

  • Please read [How to answer](https://stackoverflow.com/help/how-to-answer) and update your answer with guidelines from the guide. – fartem Feb 04 '21 at 04:54
2

If you are using Ionic with Cordova and you got here because of this error do this:

In your config.xml add

<platform name="ios">
        <preference name="UseSwiftLanguageVersion" value="5" />

You may need to remove the resource for ios and re-add it to make it work.

cordova platform remove ios
cordova platform add ios

Cheers!

Andrei Iovan
  • 107
  • 1
  • 7
1

Still, after all of that, if you're still at lost, you can add a SWIFT_VERSION directly the project file:

        80B11AAAAAAAAAAAAAAAC3E5D8 /* Debug */ = {
        isa = XCBuildConfiguration;
        baseConfigurationReference = DF5...040;
        buildSettings = {
            ...
            PRODUCT_MODULE_NAME = react-native-some-module;
            ...
            SWIFT_VERSION = "4.2";
        };
        name = Debug;
    };

Repeat for both the Debug and Release targets. That had me hop over this issue.

Patrice Gagnon
  • 1,276
  • 14
  • 14
1

I use circle ci to run tests and generate app previews on testFlight I was having this issue and was able to fix this issue by setting the SWIFT_VERSION under ios/{your_project_name}.xcodeproj/project.pcxproj.

  1. Search for SWIFT_VERSION under this file and COPY IT
    13B07F941A680F5B00A75B9A /* Debug */ = {
            isa = XCBuildConfiguration;
            baseConfigurationReference = 8F6A6E403A1DCB019B5AB844 /* Pods-heartland_charter_s_34954.debug.xcconfig */;
            buildSettings = {
                ...
                PRODUCT_NAME = heartland_charter_s_34954;
                SWIFT_OPTIMIZATION_LEVEL = "-Onone";
                SWIFT_VERSION = 5.0; // Copy this line
                ...
            };
            name = Debug;
        };
  1. Search for PRODUCT_NAME and paste the SWIFT_VERSION just under each PRODUCT_NAME block, provided that it is not already there
        13B07F951A680F5B00A75B9A /* Release */ = {
            isa = XCBuildConfiguration;
            baseConfigurationReference = CF85766339BED655A366B986 /* Pods-heartland_charter_s_34954.release.xcconfig */;
            buildSettings = {
                ...
                PRODUCT_NAME = "$(TARGET_NAME)";
                SWIFT_VERSION = 5.0; // Add it here
                ...
            };
            name = Release;
        };
  1. pod install and re run the app
Nziranziza
  • 39
  • 5
0

if you search for swift_version in "Build Settings" of your target, you will find right away :)

Medhi
  • 2,656
  • 23
  • 16