All Projects → indragiek → AlamofireRACExtensions

indragiek / AlamofireRACExtensions

Licence: MIT license
ReactiveCocoa Swift extensions for Alamofire

Programming Languages

swift
15916 projects
C++
36643 projects - #6 most used programming language

AlamofireRACExtensions

Extensions for using ReactiveCocoa (Swift) with Alamofire

This is a small set of extensions for using Alamofire with the swift-development branch of ReactiveCocoa.

Installation

Carthage

Add the following line to your Cartfile:

github "indragiek/AlamofireRACExtensions" >= 1.0

Note that AlamofireRACExtensions.framework doesn't copy its dependencies (Alamofire, ReactiveCocoa, LlamaKit) into the bundle, so you have to link and copy them in your own targets. This is so that you can use those dependencies in your own apps/libraries without them being duplicated. However, the versions of the dependencies that you link in your project must be ABI-compatible with the versions that AlamofireRACExtensions.framework links against.

Manual

Add AlamofireRACExtensions.swift to your project.

API

The main method is Alamofire.Manager.rac_request(request:serializer:):

public func rac_request(request: URLRequestConvertible, serializer: Request.Serializer) -> SignalProducer<(AnyObject, NSHTTPURLResponse), NSError>

There are convenience methods built on this one for getting responses as data, JSON, or property list. All methods return a SignalProducer, which means that:

  • The HTTP request isn't started until start() has been called on the SignalProducer
  • Each invocation of start() on the same SignalProducer causes a new HTTP request to be started

Example

let manager = Manager(configuration: NSURLSessionConfiguration.defaultConfiguration())
let request = NSURLRequest(URL: NSURL(string: "http://httpbin.org/get")!)
manager.rac_JSONWithRequest(request)
    .start(next: { (object, _) in
        if let JSONDictionary = object as? [String: AnyObject] {
            println(JSONDictionary)
        } else {
            fatalError("JSON object is not a dictionary")
        }
    }, error: { error in
        println("Request failed with error \(error)")
    })

The unit tests contain more usage examples.

Contact

License

AlamofireRACExtensions is licensed under the MIT License. See LICENSE for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].