Alamofire Xcode 8 Swift 3 results in 786 compile errors

22,595

Solution 1

Upgrading to the latest Cocoapods (at the time of this answer: version 1.1.0.beta.2) via the command:

gem install cocoapods --pre seemed to solve the issue for my circumstance.

Solution 2

I was able to get it working:

update:

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

target 'PROJECT NAME HERE' do
  # Comment this line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!
  pod 'Alamofire',
    :git => 'https://github.com/Alamofire/Alamofire.git',
    :branch => 'swift3'

end

pod update Alamofire

It should update to 4.0.0-beta.2

There are a few changes when getting a request:

old:

Alamofire.request(URL_NAME_HERE, withMethod: .get).responseJSON { response in
     //Code here.
}

new:

Alamofire.request(URL_NAME_HERE, method: .get).responseJSON { response in
     //Code here.
}

Hope this helps.

Solution 3

You should use the master branch now since the swift3 branch has been merged there. Moreover it's normal for the Xcode Migrator to show that many errors. What it's doing s compiling the code thinking it's a legacy Swift version but since it's already in Swift 3.0, the errors are to be expected. Finally, Xcode is asking you to convert to modern Swift syntax probably because you haven't used the latest version of Cocoapods to install Alamofire.

NB: event though Cocoapods tells you to use gem install cocoapods --pre, I prefer using gem update cocoapods --pre. Else, the older version of Cocoapods stays and still is used when using pod update. Check what version you're using with pod --version.

Solution 4

Update the pod to 1.1.0.rc using the below command.

sudo gem install cocoapods

use the blow snippet at the end.

post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['SWIFT_VERSION'] = '3.0' end end end

this helps.

Solution 5

The solution is to change your request from this

pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'swift3'

to this

pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'master'
Share:
22,595
Aaron
Author by

Aaron

Developer in Portland, OR.

Updated on April 09, 2020

Comments

  • Aaron
    Aaron about 4 years

    I am using the Xcode 8.0 GM. I created a default single-view app with my deployment target set to 9.0.

    In my Podfile I'm targeting the bleeding edge Swift 3 branch:

    source 'https://github.com/CocoaPods/Specs.git'
    platform :ios, '9.0'
    use_frameworks!
    
    target 'MyProject' do
        pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'swift3'
    end
    

    I run pod install and get ... Installing Alamofire (4.0.0-beta.2) ... fantastic, no problems. I open MyProject.xcworkspace.

    This pops up:

    convert Alamofire to latest syntax

    I can't hit later because it tells me:

    Xcode 8 will not be able to build the target “Alamofire”, and certain editing features will not function properly until the Swift source code in this target has been converted.

    That's no good, I want to build it. So I hit "Convert". It gives me options:

    convert to Swift 3

    Well that's what I want, Swift 3. Looks good, I hit "next".

    select targets

    It defaults to these 3 selected targets. Ok fine, I hit next.

    error 1 error 2

    What in God's Holy name...

    I want to use Alamofire's swift3 bleeding edge branch on an Xcode 8, Swift 3 project targeting iOS 9.0. Where did I go wrong and how can I get this working? FWIW I get a bunch of errors trying to use Alamofire's Swift 2.3 branch so I know it's something I'm doing wrong.