Caleb Kleveter
Caleb Kleveter

Reputation: 11494

Swift compiler is confusing version 2 and 3

I installed a cocoapod to a project and ran the converter on it to change it over to Swift 3.

The issue is the compiler thinks that I am using Swift 2, and is throwing errors on proper Swift 3 syntax (a whopping 129 errors). For example:

internal enum Error: ErrorProtocol {
    case noCentralManagerSet
    case busy
    case interrupted
}

Throws use of undeclared type 'ErrorProtocol'.

enter image description here

What is wrong?

The Swift 3 code that I wrote is not throwing compiler errors.

Here is the output of xcodebuild -showsdks:

2016-07-01 14:16:05.850 xcodebuild[30824:2848916] [MT] PluginLoading: Required plug-in compatibility UUID 1637F4D5-0B27-416B-A78D-498965D64877 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/WebDevSupport.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2016-07-01 14:16:05.864 xcodebuild[30824:2848916] [MT] PluginLoading: Required plug-in compatibility UUID 1637F4D5-0B27-416B-A78D-498965D64877 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/WebDevelopment.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2016-07-01 14:16:05.911 xcodebuild[30824:2848916] [MT] PluginLoading: Required plug-in compatibility UUID 1637F4D5-0B27-416B-A78D-498965D64877 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/WakaTime.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2016-07-01 14:16:05.944 xcodebuild[30824:2848916] [MT] PluginLoading: Required plug-in compatibility UUID 1637F4D5-0B27-416B-A78D-498965D64877 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Rayrolling.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2016-07-01 14:16:05.967 xcodebuild[30824:2848916] [MT] PluginLoading: Required plug-in compatibility UUID 1637F4D5-0B27-416B-A78D-498965D64877 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/CocoaPods.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2016-07-01 14:16:05.997 xcodebuild[30824:2848916] [MT] PluginLoading: Required plug-in compatibility UUID 1637F4D5-0B27-416B-A78D-498965D64877 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcplugin' not present in DVTPlugInCompatibilityUUIDs
OS X SDKs:
    OS X 10.12                      -sdk macosx10.12

iOS SDKs:
    iOS 10.0                        -sdk iphoneos10.0

iOS Simulator SDKs:
    Simulator - iOS 10.0            -sdk iphonesimulator10.0

tvOS SDKs:
    tvOS 10.0                       -sdk appletvos10.0

tvOS Simulator SDKs:
    Simulator - tvOS 10.0           -sdk appletvsimulator10.0

watchOS SDKs:
    watchOS 3.0                     -sdk watchos3.0

watchOS Simulator SDKs:
    Simulator - watchOS 3.0         -sdk watchsimulator3.0

Upvotes: 1

Views: 401

Answers (3)

Edison
Edison

Reputation: 11987

Two things help me manage cases like these.

Because Xcode auto-opens previous projects that were never closed if you open Project A in Xcode 7 then open Xcode 8 to start something new Xcode 8 will also open that same Project A. So you actually have to close project A in Xcode 8 or else you'll get tons of errors and you might think you're working in Xcode 7 because Project A is open. At this point Project A is open in Xcode 7 and Xcode 8.

Also I name my Project folder projectName - Swift 2 then duplicate it and name that one `projectName - Swift 3.

Of course we have version control but just to be safe I like having two separate folders for Swift 2 / 3 because things can get crazy with the same project open in two versions of Xcode.

Since you also have to tell Terminal to use a separate directories for pod installs it's safer because there's no overlapping.

Upvotes: 0

Sulthan
Sulthan

Reputation: 130102

You can set Swift version for every target:

Legacy Swift Language Version

Your project got probably set to Yes.

The SDK has no part in the compilation process.

Upvotes: 3

Mtoklitz113
Mtoklitz113

Reputation: 3878

I think I know what is the problem. You've directly converted all the files from Swift2.0 to Swift3. It wont work that way. I suggest you delete the pods and clone the Swift3 branch of this (which i believe you are using) and copy the source directory to your project for now as it doesn't say which version of that repo is swift-3 usable. It should solve your issue. :)

Upvotes: 1

Related Questions