13

I'm relatively new to XCode and iOS. My background for understanding how to add libraries/dependencies to a project is in the world of Java and Maven.

I need to add AFNetworking to my project and have been unable to do so successfully.

First, I tried going to my project -> Build Phases -> Link Binary With Libraries, clicking the "+" button, and then search for AFNetworking from the list. It wasn't in the list.

So, I figured I'd have to add it using the "Add Other..." option. Which means, of course, I'd need to download AFNetworking somehow. I'm not sure I was able to download it in the correct form -- it seems all I could get was the AFNetworking project itself, rather than a framework (if I understand correctly, frameworks are analogous to jars? Can you generate a framework by building an iOS project in a certain way?). I downloaded it from their GitHub page. (I also tried their "Getting Started" guide, but it had me using CocoaPods, which I couldn't get to work right and I'd rather avoid it for now.)

I've tried adding project files and folders from AFNetworking just to see if they worked (but of course they don't -- I think I need some sort of .framework file).

Bottom line: I can't seem to find a way to add AFNetworking to my project. How can I do it?

Jagat Dave
  • 1,643
  • 3
  • 23
  • 30
James Dunn
  • 8,064
  • 13
  • 53
  • 87

4 Answers4

14

It sounds like you got the first part down, which is downloading it from the GitHub page.

When I follow this tutorial, it shows how they imported AFNetworking into their own sample project (that is, you'll see a "AFNetworking" group in the list of files and folders along the left side of your Xcode window).

Once AFNetworking is building along with the rest of your code in your project, you should be able to call into the various AFNetworking API's from your code. You'll need to make certain to add in the appropriate "#import "AFNetworking.h"" lines into your source code files from which you'll be calling AFNetworking.

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • 2
    Wow, it was as simple as the tutorial said. (Simpler, actually, as I didn't have to tell the compiler to not use ARC with it). Adding it as a framework would have been neater than adding it as a directory, but I'll take whatever works at this point. For anyone using this answer, just scroll a third of the way down the tutorial page until you come to the heading "Adding AFNetworking to the Mix". – James Dunn Jan 22 '14 at 20:29
  • Any idea how to do it in Swift? – MK Yung Jun 08 '15 at 13:45
  • 1
    @MKYung You can either do [Objective-C bridging](http://stackoverflow.com/questions/24120402/swift-and-afnetworking-integration) or you can use [AlamoFire](https://github.com/Alamofire/Alamofire), which [does have native Swift support](http://nshipster.com/alamofire/) (but isn't as as fleshed out as AFNetworking). – Michael Dautermann Jun 08 '15 at 17:29
3

Use pods, than you wont have to upload AFNetworking to your github project, and there is no worry about wrong linkers etc.

Use pods: install pods

Instalation AFNetworkign with pods: install AFNetworking

edzio27
  • 4,126
  • 7
  • 33
  • 48
1

I believe if you download their code you can generate the .a file using the process in this stack overflow answer: (obviously replacing the project they are getting from gihut with the project you found) How to create framework from Xcode 4 project?

Community
  • 1
  • 1
Maroon5Five
  • 147
  • 7
  • In the answer you linked to, it says, "ensure that iOS Static Library is selected in the scheme drop-down, and then hit run." -- What scheme drop-down? I don't see one. – James Dunn Jan 22 '14 at 19:21
1

Use this Manager to help you use AFNetwork.

Jagat Dave
  • 1,643
  • 3
  • 23
  • 30
Viton
  • 67
  • 5