32

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.

Aaron
  • 6,466
  • 7
  • 37
  • 75

10 Answers10

23

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.

Aaron
  • 6,466
  • 7
  • 37
  • 75
  • I'm having the same issue. I've updated Cocoapods to 1.1.0.beta.2, tried to install Alamofire again, but it is still not working for me... – Rados Sep 08 '16 at 08:06
  • 1
    @Rados You should check what version of Cocoapods is used with `pod --version`. The older versions are still there being used so you could use `gem cleanup`to keep only the latest release of Cocoapods. – Jonas Zaugg Sep 10 '16 at 05:54
  • It was a problem with Xcode itself (I was using Xcode 8 beta 6). When I downloaded Xcode GM everything went as expected. – Rados Sep 11 '16 at 10:56
  • Thanks, it help me very much! – javimuu Feb 14 '17 at 09:45
  • This did nto help, itfact it got worse. I got 4 errors on this line of code ` urlSession = URLSession(configuration: URLSessionConfiguration)` – Siddharth Jun 15 '17 at 06:50
7

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.

weskam
  • 79
  • 5
  • They specifically mention to write a question on Stack Overflow and tag it with the "Alamofire" tag. I almost put sentence in my original question expecting an answer like this. – Aaron Sep 08 '16 at 05:09
  • What did you do when the "Convert to current Swift syntax" prompt appeared when you opened the project? And you're using Xcode 8 GM? – Aaron Sep 08 '16 at 06:00
  • I never converted. Yeah, Xcode 8 GM (Been using swift 3 for awhile now). If you have converted, revert back to your working copy. – weskam Sep 08 '16 at 06:05
  • I was able to create and build a new project. I'm going to assume you are opening the "xcworkspace" after you have installed the pod? See Podfile update above. Thats what I'm using line for line. No problems. – weskam Sep 08 '16 at 06:23
  • That's strange. It automatically shows that prompt when I open the project. So you created a new empty project, created a podfile with those specs, ran pod install, then reopened the xcworkspace and it didn't prompt you at all and worked? It always prompts me to convert the target "Alamofire" to the latest swift syntax after I `pod install` then open the xcworkspace. – Aaron Sep 08 '16 at 06:26
  • Correct, and it never asks me to convert the syntax. – weskam Sep 08 '16 at 06:42
  • I wish I could accept this as the answer if only I could reproduce your steps and get it to work. – Aaron Sep 08 '16 at 06:43
  • While your answer didn't solve my issue it indirectly helped me diagnose it with the sample project you linked. I gave you an upvote for good measure as it technically could be considered a solution. – Aaron Sep 08 '16 at 07:03
  • Thanks. I completely forgot about the Cocoapods 1.1.0.beta.2 – weskam Sep 08 '16 at 07:09
  • 2
    There is no branch called swift3 – ossamacpp Sep 14 '16 at 02:07
  • 1
    After swift 3 official release there's no swift3 branch anymore. You have to use instead: pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => '4.0.0-beta.2' but there are 404 issues... – Andrea.Ferrando Sep 14 '16 at 15:35
7

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.

Jonas Zaugg
  • 3,005
  • 2
  • 15
  • 21
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.

Rajesh Panda
  • 197
  • 1
  • 4
4

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'
Nour
  • 1,458
  • 1
  • 18
  • 27
2

I solved a similar issue by using

pod 'Alamofire', '~> 4.0'

in the pod file. I did have to adjust to a higher minimum deployment target.

Nakul Sudhakar
  • 1,574
  • 1
  • 24
  • 24
2

I solved similar issue by using :

platform :ios, '9.0'
use_frameworks!
target 'PROJECT NAME HERE' do
pod 'Alamofire'
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
kvorobiev
  • 5,012
  • 4
  • 29
  • 35
urvashi bhagat
  • 1,123
  • 12
  • 15
0

I had the same issue, but I uninstalled cocoapods, uninstalled alamofire, then updated my cocoa pods to 1.1.0.beta.2, then used the swift3-rebased branch of Alamofire in my pod file

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

opened my Project.xcworkspace file and all the compiling errors for Alamofire were gone.

Cory Billeaud
  • 127
  • 1
  • 1
  • 11
0

Not sure if this helps anyone but just in case.. I tried to add Alamofire to a sample quick app on Xcode 8.0 GM using the CocoaPods standalone app.. I kept getting the Convert to swift 2.3 or 3.0 window.. but then I tried from the command line to pod update and it worked. Have no idea why.. I assume the underlying commands for the standalone app are the same.. so not sure what made the difference. In any case after 30 minutes of wasted time mine works.

CocoaPods standalone Mac app screenshot

This is the command line screenshot.. same pod file

enter image description here

Zsolt
  • 3,648
  • 3
  • 32
  • 47
  • Easy: the CocoaPods App uses the release version of CocoaPods tool (1.0.1) which doesn't take Swift 3 into account whereas you've probably already updated the command-line tool to one of the pre-release 1.1.0 – Jonas Zaugg Sep 22 '16 at 21:36
0

You need to use version 4.0pod 'Alamofire', '~> 4.0' notice that CocoaPods 1.1 is needed.

Sam
  • 97
  • 10