So I am trying to add some Swift code to an existing project created in XCode 5 and I get a crash whenever I try to automatically generate a bridging header. Looking in my project settings, I think it is because there are no Swift Compiler settings. Anyone know of a way to migrate a project to XCode 6 settings or do I need to re-create the project?
问题:
回答1:
The only solution I've found for this is to create a new target. Make sure to select "Swift" as the language choice for the new target. Something in the creation of a target with this selection enables the Swift build settings.
Update: Creating a new target containing Swift worked because of what it contained. When I removed the template Swift files from the new target the Swift-specific build settings disappeared from the project again.
The real indicator to Xcode on whether to show those build settings is whether the target contains at least one .swift
file. So, the easiest solution is to simply add a new Swift file. This also triggers Xcode to prompt you about automatically creating an Objective-C bridging header - which you'll need in any project that has some Objective-C in it.
回答2:
I was able to work around this by manually adding some Swift settings to the project.pbxproj
file.
In the attributes block of the PBXProject section, add:
LastSwiftUpdateCheck = 0720;
In the XCBuildConfiguration section, add this to the Debug build settings for the project (the first and larger block of settings):
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
And add this to the Debug build settings for the target:
OTHER_SWIFT_FLAGS = "-DDEBUG";
And this to the Release build settings for the target:
OTHER_SWIFT_FLAGS = "";
When you reopen the project, the Swift settings will be available.