Last active
October 17, 2016 01:37
-
-
Save michaelteter/442894d8ccdc9ada3cd2f2513dbf1849 to your computer and use it in GitHub Desktop.
Xcode 8, Swift 3, and Alamofire - getting it setup and building
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Alamofire has recently been updated. Now it seems to support Swift 3 from its main (master) branch. | |
Below are instructions that should work :) | |
------------------------------------------------------------------------------------------------ | |
CURRENT INSTRUCTIONS --------------------------------------------------------------------------- | |
1. Install cocoapods | |
$ sudo gem install cocoapods | |
2. create an xcode project | |
3. open a terminal and change directory to that project folder | |
4. initialize a podfile for the project: | |
$ pod init | |
5. edit the Podfile with a text editor, and make it look like this (with your project name in place of 'ExampleProject') | |
platform :ios, '10.0' | |
use_frameworks! | |
target 'ExampleProject' do | |
pod 'Alamofire', '~> 4.0' | |
end | |
6. install the pods: | |
$ pod install | |
6.1 The above step may not work correctly; it did not for me. If it fails, try this: | |
$ pod repo update | |
# Much stuff will print in your terminal as it updates cocoapod repos | |
6.2 Try to install the Alamofire pod again: | |
$ pod install | |
# You should see something like "Installing Alamofire (4.0.0)" in the output that follows | |
7. Close Xcode, and open the <projectname>.xcworkspace file. | |
8. Edit your ViewController.swift, adding 'import Alamofire' on the line below the existing 'import UIKit' | |
9. CMD-B to build the project | |
The project should build with no errors. | |
Xcode may warn you about outdated project file settings, and in my testing it was ok to accept their recommended changes. But it's also a good idea to commit your code first, then allow it to change the project file, and then test to make sure it still builds. | |
Example project: https://github.com/michaelteter/AF4 | |
------------------------------------------------------------------------------------------------ | |
OLD INSTRUCTIONS BELOW ------------------------------------------------------------------------- | |
Getting Alamofire to install and build on an Xcode 8 Swift 3 project can be challenging (during these fast-changing times in the Xcode, iOS, and Swift times). | |
EXAMPLE PROJECT: https://github.com/michaelteter/AF3 | |
1. install the latest version of Cocoapods: | |
$ sudo gem install cocoapods --pre | |
2. create an xcode project | |
3. open a terminal and change directory to that project folder | |
4. initialize a podfile for the project: | |
$ pod init | |
5. edit the Podfile with a text editor, and make it look like this (with your project name in place of 'ExampleProject') | |
target 'ExampleProject' do | |
use_frameworks! | |
pod 'Alamofire', | |
:git => 'https://github.com/Alamofire/Alamofire.git', | |
:branch => 'swift3-rebased' | |
end | |
6. install the pods: | |
$ pod install | |
... some time will pass ... | |
You should now have a new xcworkspace file. In this example it is ExampleProject.xcworkspace | |
7. Using Xcode, open ExampleProject.xcworkspace | |
8. Edit your ViewController.swift, adding 'import Alamofire' on the line below the existing 'import UIKit' | |
9. CMD-B to build the project | |
The project should build with no errors. | |
TROUBLESHOOTING | |
* Make sure you are opening the <projectname>.xcworkspace file, NOT the standard <projectname>.xcodeproj file. | |
* Check your Podfile.lock file. It should look pretty much like this: | |
$ cat Podfile.lock | |
PODS: | |
- Alamofire (4.0.0-beta.2) | |
DEPENDENCIES: | |
- Alamofire (from `https://github.com/Alamofire/Alamofire.git`, branch `swift3-rebased`) | |
EXTERNAL SOURCES: | |
Alamofire: | |
:branch: swift3-rebased | |
:git: https://github.com/Alamofire/Alamofire.git | |
CHECKOUT OPTIONS: | |
Alamofire: | |
:commit: 2e702055932b9cdce6863d46c25d1770f64f75a6 | |
:git: https://github.com/Alamofire/Alamofire.git | |
SPEC CHECKSUMS: | |
Alamofire: 7f837be535fe424db2b87d9117f13836939719ca | |
PODFILE CHECKSUM: c17f593e8b44df0bcd9a0f9436b3b50120378678 | |
COCOAPODS: 1.1.0.beta.2 | |
* If it's not working, you may be somehow using the wrong/older version of cocoapods; | |
Or you may have an old version of Alamofire | |
* Worst case scenario, you can manually install following https://github.com/Alamofire/Alamofire/tree/swift3#manually | |
!!! If you follow the manual installation guide, be sure to use the following when adding the submodule | |
$ git submodule add -b swift3-rebased https://github.com/Alamofire/Alamofire.git |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great job, thank you !