Compile Swift on 10.9?

2019-04-05 03:36发布

问题:

Until this afternoon, when I downloaded the final Xcode 6, I was able to play around with Swift on my 10.9 machine. Now I get this error:

OS X targets using Swift cannot be built against an SDK older than 10.10, but the effective SDK is 10.9.

I had saved my copy of Xcode 6B7, but now opening the project in that version also causes the same error.

Anyone have a fix? I do not want to install 10.10 on this machine.

回答1:

Xcode 6.0 is only going to support using Swift with iOS. Using Swift with Mac OS X is not supported in this version of Xcode, and you will need to get Xcode 6.1 beta for that. Previous betas of Xcode 6.0 has support of Swift for OS X, but that was because Xcode 6.1 beta wasn't out at that time.

From the Xcode 6.0 release notes:

Swift Support for OS X

*A future version of Xcode to be released along with OS X Yosemite will add Swift support for OS X, including playgrounds and REPL. Xcode 6.0 only supports Swift for iOS projects and playgrounds. A beta release of Xcode with Swift support for both OS X and iOS is available at developer.apple.com/xcode/downloads/



回答2:

Ok, so here's the scoop:

After downloading the GM you will have a non-functional Xcode, Apple forgot to include the sdk in the app bundle. So now you have to download the 6.1 beta as well, Show Package Contents, and go to the folder:

/Volumes/Xcode/Xcode-Beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer

Note I have opened the app bundle from the disk image, thus the volume name. Inside that SDKs folder you will find MacOSX10.9.sdk and MacOSX10.10.sdk. The GM release is missing the later. So make a copy of that somewhere handy, like your desktop.

OK, now find the same path in the GM version. Mine's installed in my Applications folder, so it's here:

/Applications/Xcode 6.app/Contents/Developer/Platforms/MacOSX.platform/Develope

You will note that the MacOSX10.10.sdk folder is missing. Nice. Ok, copy the version from the beta into this folder.

Restart Xcode, open your project and Clean. Now look VERY CAREFULLY for every setting for SDK or deployment target. The SDK has to be 10.10, the deployment target has to be 10.9. This appears in many places on several screens, so look carefully.

Compiles and runs. And fixes the crashes I was seeing in Xcode in B6 and B7.



标签: swift xcode6