Programming

Xcode 9 Swift 언어 버전 (SWIFT_VERSION)

procodes 2020. 8. 11. 20:43
반응형

Xcode 9 Swift 언어 버전 (SWIFT_VERSION)


최근에 xcode를 버전 9로 업데이트했습니다. 그 전에 Xcode 8.x에서 사용할 때마다 pod update코드를 Swift 3로 변환하고 오류를 해결하는 업데이트 코드가 표시됩니다. 하지만 이제는 다음과 같은 오류가 발생합니다.

"Swift 언어 버전"(SWIFT_VERSION) 빌드 설정은 Swift를 사용하는 대상에 대해 지원되는 값으로 설정되어야합니다. 이 설정은 빌드 설정 편집기에서 설정할 수 있습니다.

이 오류에 대해 시도했지만 Build Settings > Swift Language VersionSwift 3.2 였지만 업데이트 호출이 Alamofire와 같은 일부 포드를 다시 설치했고 코드를 Swift 3으로 변환하기 위해 Xcode 8.x를 설치하라는 메시지가 표시되었으므로이를 설치해야합니다. 최신 Xcode가있는 추가 버전? 그렇다면 Xcode 9와 함께 Xcode 8을 어떻게 설치할 수 있습니까?


질문에 대한 답변 : 프리미엄 개발자 계정 (apple id)이있는 경우 Apple 다운로드 포털
에서 Xcode 8.x를 다운로드 하거나 Xcode 8.3.3을 다운로드 할 수 있습니다 (또는 참조 : Xcode의 이전 버전 다운로드 위치 ). 단일 (mac) 시스템에서 Xcode 9 및 Xcode 8.x를 모두 설치하고 사용할 수 있습니다. ( Command Line Tools터미널에서 작동하려면 두 버전의 Xcode를 모두 지원 하는지 확인하십시오 ( 'Command Line Tool'설치 방법 참조 ))


힌트 : 코드 엑스 코드 (9 개) 호환 스위프트 버전 (스위프트 3.2 4)로 마이그레이션하는 방법
엑스 코드 (9)에서 변환 / 마이그레이션을 가능 Swift 3.0으로 Swift 3.2/4.0만. 따라서 프로젝트의 현재 Swift 언어 버전이 3.0 미만이면 Xcode 8.x를 사용하여 Swift 3 호환 버전으로 코드를 마이그레이션해야합니다.

이것은 Xcode 9가 마이그레이션 중에 3.0 미만의 Swift 언어를 식별하는 경우 표시하는 일반적인 오류 메시지입니다.

여기에 이미지 설명 입력


Swift 3.2는 Xcode 9 및 Xcode 8에서 모두 지원됩니다.

프로젝트 ► (프로젝트 대상 선택) ► 빌드 설정 ► (검색 창에 'swift'입력) Swift Compiler Language ► Swift Language Version ► 언어 목록을 클릭하여 엽니 다.

여기에 이미지 설명 입력



Xcode 8을 사용하여 소스 코드를 Swift 2.0에서 3.2로 변환 한 다음 Xcode 9 (Swift 3.2 또는 4)를 계속합니다.


For easier migration of your code, follow these steps: (it will help you to convert into latest version of swift supported by your Xcode Tool)

Xcode: Menus: Edit ▶ Covert ▶ To Current Swift Syntax

여기에 이미지 설명 입력


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 as shown in the image below

빌드 설정

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.


I just got this after creating a new Objective-C project in Xcode 10, after I added a Core Data model file to the project.

I found two ways to fix this:

  1. The Easy Way: Open the Core Data model's File Inspector (-1) and change the language from Swift to Objective-C

핵심 데이터 모델 언어 변경

  1. Longer and more dangerous method

The model contains a "contents" file with this line:

<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="14460.32" systemVersion="17G5019" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">

In there is a sourceLanguage="Swift" entry. Change it to sourceLanguage="Objective-C" and the error goes away.

To find the "contents" file, right click on the .xcdatamodeld in Xcode and do "Show in Finder". Right-click on the actual (Finder) file and do "Show Package Contents"

Also: Changing the model's language will stop Xcode from generating managed object subclass files in Swift.


This can happen when you added Core Data to an existing project.
Check the:
<Name>/<Name>.xcdatamodeld/<Name>.xcdatamodel/contents
file.
This file contains an entry "sourceLanguage" that (by default) might have been set to "Swift". Change it to "Objective-C".


I just click on latest swift convert button and set App target build setting-> Swift language version: swift 4.0,

Hope this will help.


This Solution works when nothing else works:

I spent more than a week to convert the whole project and came to a solution below:

First, de-integrate the cocopods dependency from the project and then start converting the project to the latest swift version.

Go to Project Directory in the Terminal and Type:

pod deintegrate

This will de-integrate cocopods from the project and No traces of CocoaPods will be left in the project. But at the same time, it won't delete the xcworkspace and podfiles. It's ok if they are present.

Now you have to open xcodeproj(not xcworkspace) and you will get lots of errors because you have called cocoapods dependency methods in your main projects.

So to remove those errors you have two options:

  1. Comment down all the code you have used from cocoapods library.
  2. Create a wrapper class which has dummy methods similar to cocopods library, and then call it.

Once all the errors get removed you can convert the code to the latest swift version.

Sometimes if you are getting weird errors then try cleaning derived data and try again.


maybe you need to download toolchain. This error occurs when you don't have right version of swift compiler.


In my case, all warn disappeared after I directly changed swift version from 2.x to 4.0 in build settings except two warn.

These warning related to myprojectnameTests and myprojectnameUITests folder. I didn't notice and I thought its relate to direct immigration from Xcode 7 to Xcode 9 and I thought I couldn't solve this problem and I should install missed Xcode 8 version.

In my case, I deleted these folders and all warns disappeared, but you can recreate this folder and contains using this:

file > new > target > (uitest or unittest extensions)

and use this article for create test cases: https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/04-writing_tests.html

참고URL : https://stackoverflow.com/questions/46338588/xcode-9-swift-language-version-swift-version

반응형