The “Swift Language Version” (SWIFT_VERSION) build setting error with project in Objective C - objective-c

So i just went to build my app after adding in core data to update my app to store and fetch some information and i got this error. (I am using XCode 9.2)
The “Swift Language Version” (SWIFT_VERSION) build setting must be set
to a supported value for targets which use Swift. This setting can be
set in the build settings editor.
Now whats confusing me is this in an Objective C app and surely the swift version shouldn't matter. I have browsed some threads on here stating that i need to update build setting to Swift 3.0 or to set values to Yes then back to No, however i have none of these fields when i search for Swift in the search bar.
Is this just a bizarre bug or have i mistakenly added some swift code?
Any ideas would help, thanks.

I experienced this exact same issue after adding Core Data to an Objective-C framework I was working on.
I discovered that the reason I was getting the "Swift Language Version" warning was that the Code Generation language in the .xcdatamodel defaulted to Swift. Once I changed this back to Objective-C, the warning went away.
You can find this property in the File Inspector when you have the .xcdatamodel selected in the Project Navigator.

For Objective C Projects created using Xcode 8 and now opening in Xcode 9, it is showing the same error as mentioned in the question.
To fix that, Press the + button in Build Settings and select Add User-Defined Setting.
Then in the new row created add SWIFT_VERSION as key and 3.2 as value like below.
It will fix the error for objective c projects.

Related

How do I get a Swift Cocoapod working in an Objective C project?

I am trying to get the Swift Charts library for iOS working in my Objective-C project. Here's what I've done so far:
(1) Installed the Charts pod
(2) Under "Build Options", set "Embedded Content Contains Swift Code" to YES
(3) Followed the Apple doc for importing external frameworks and put '#import Charts;' in one of my .m files. I set the Defines Modules to YES in my project Target--which makes Xcode recognize the import statement. BUT the doc says to set it in the Framework--which I don't know how to access that--so that may be the problem?
I'm getting many errors popping up in files of the Charts Cocoapod itself (Things like "Expected ',' separator"), which I'm sure is not because they are actual errors (this is a well maintained library), but because something is not hooked up right. What am I doing wrong?
I have used ChartsPod recently in objective-c project. Yes it was headache to set up Chart Pods with the project. Few things you need to look carefully while importing swift pod.
Follow author instructions carefully.
Have you created Bridging Header to tell compiler it's a swift code? If not then read authors instructions carefully (Chart-iOS) or read BridgingHeader
In Target->Build Phases->Target Dependencies add Chart-iOS
Hope this will help.

Xcode cannot find ProductModuleName-Swift.h

I'm attempting to import my "-Swift.h" file into one of my Objective-C .h files but xcode keeps telling me that the file doesn't exist
#import "Aesculus-Swift.h"
If I command click on the file name it will take me to the generated header file so I know it exists. Why is xcode not able to find it?
This seems like just another issue with Xcode and it's complex tool chain of static analysers and compilers.
Openradar lists radar://21362856 - Swift to Objective-C bridging is unreliable. I am sure there are more but I stopped looking after finding one for this example.
The author imarcelv notes in the description:
I asked a Swift engineer at WWDC in a lab and even he didn't know how to fix this issue.
Steps to Reproduce:
Add a ramdom Swift class to an Objective-C project
Add the #import "ModuleName-Swift.h" file that Xcode generates automatically
Try to use it or just try to compile the project
From time to time it simply doesn't work
It's probably best to file a radar on this issue as it seems that others are already calling it out.
One other thing you could try...
Historically, it was possible for Xcode to completely lose it's syntax highlighting and you could always find out what files the static analyser was giving up on by increasing log level of clang.
I'm not sure if it's still relevant but if I was in your position I'd be trying this command:
defaults write com.apple.dt.Xcode IDEIndexingClangInvocationLogLevel 3
This generates logs you can search with using Console.app for just xcode to highlight the messages. You'll want to trash the derived data of your project to force it to re-compile things.
Although not the same issue as what you're seeing, I have had this post on the syntax highlighting issue bookmarked for years for the above defaults write command to try in times like these.
I solved this recently by adding the following entry to my .xcconfig (you could add it in Xcode's Build Settings > User Header Search Paths if you prefer).
USER_HEADER_SEARCH_PATHS = $(BUILT_PRODUCTS_DIR)/MyFramework.framework/Headers
This tells the compiler to search for headers in the build output directory, which is where Xcode puts the generated header (at least in the case of this framework).
In my case this is a directory like ~/Library/Developer/Xcode/DerivedData/MyProject-LongCode/Build/Products/Debug-iphonesimulator/MyFramework.framework/Headers/MyFramework. You might find your generated header in there too.
Xcode's header and dependency management is a hot mess, and it's not surprising that it doesn't work for you.
I had trouble with this stuff & found that your -Swift file is the Product name of your Target ( not just the name of your Target ) . I found the details here helpful: http://ericasadun.com/2014/08/21/swift-calling-swift-functions-from-objective-c/
When you encounter such situation, just find your kinda "ProductName-Swift.h" file by just cmnd+click on it (even if xcode shows warning about it is not found, the #import "Aesculus-Swift.h" string is still clickable) and then in opened code editor window choose context menu and "Show in Finder" item, then explicitly add it to your project.

Migrate and add Swift to existing Objective-C project

I have an old project that I built on iOS 7 with Xcode 5. Recently I upgraded to Xcode 6 GM. I opened that project in new Xcode and tried adding this swift code to one of my method in v1Album.m file.
let alertController = UIAlertController(title: "Hey AppCoda", message: "What do you want to do?", preferredStyle: .Alert)
I get an error saying Use of undeclared identified let
I have been searching, trying to see what I need to do, what settings I need to change in my project in order for it to start recognizing swift code. Every tutorial online I see is explaining how to start writing swift code in a brand new project. All I need is to be pointed in the right direction.
EDIT:
What I have read so far on migrating project to swift from Apple Doc here is that
in order to write swift code I need a brand new swift class
I need to rewire all my objective-c code from v1Album.m to v1Album.swift
Then I deselect v1Album.m from my project.
I cannot use swift code directly in v1Album.m without first defining that method in v1Album.swift file and then using a bridging header.
Basically I cannot do what I am trying to do i.e. write straight up swift code in *.m file.
Please correct me, I maybe completely wrong.

Cannot compile EZAudio in Xcode 6 beta 5

I'm attempting to use EZAudio in my Swift application. I've added the Objective C bridging header, however I still receive the following error:
Function definition is not allowed here (line 34) in EZPlot.h
With this line:
typedef NS_ENUM(NSInteger,EZPlotType){
I realise it's early days with this version of Xcode, but has anyone managed to get the thing to compile?
Had a prefix header to your project will resolve the problem. Don't forget to change your build settings after that.
see the edit on this post => https://github.com/syedhali/EZAudio/issues/63#issuecomment-47230912

Some Parse methods not working in iOS SDK

I added the Parse SDK today (1.2.15) to an existing project which targets iOS7 and is built in Xcode5. I followed the instructions on https://parse.com/apps/quickstart#ios/native/existing exactly. Some things work, like creating and saving a PFObject. Certain functions however cannot be found by the compiler. For instance [PFUser enableAutomaticUser]; generates the error
AppDelegate.m:21:13: No known class method for selector 'enableAutomaticUser'
and [PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions]; generates the error
AppDelegate.m:20:6: Use of undeclared identifier 'PFAnalytics'
Are the docs out of date and have these methods moved? I have tried restarting Xcode and cleaning my project. I can see the PFAnalytics.h file if I expand Parse.Framework in Xcode, and when I look at PFUser.h I can see a declaration of enableAutomaticUser;. Why can Xcode see some Parse classes and methods but not others?
My problem was that Framework Search Paths in Build Settings contained two directories, and one was invalid, resulting in this very strange behavior where some methods in Parse worked and others didn't.