MatterGoal
MatterGoal

Reputation: 16430

Importing Alamofire in Project that targets iOS 7

I checked the new Alamofire installation steps.

Since I need to target iOS 7.0 I wonder if importing the Alamofire.swift is enough to make it works or not?

Why the documentation states to wrap the functions around a Struct Alamofire? is that needed to call functions as they were within a Namespace? and in that case have I to wrap the whole file or single functions?

Upvotes: 7

Views: 2150

Answers (2)

Tom Manterfield
Tom Manterfield

Reputation: 7083

So with the readme.md + some scouring of comments on their issues, the instructions we find are wrapping all of the top level members in

struct Alamofire {
    all original code ...
}

but in reality this doesn't seem to work quite that easily.

The whole file is pretty big, so here's a gist (not mine) with modifications to make the basic idea work: https://gist.github.com/ChocolateMinht/00aa610da1b4e6c4bed6

You are right in thinking that is needed to make the calls as if they are namespaced.

With the above you can just call Alamofire.request(...) as you would if it were imported as a framework in iOS 8+

Upvotes: 1

JERC
JERC

Reputation: 1624

You just have to add this:

//put this on alamofire.swift, then call it as Alamofire.manager.your_method
struct Alamofire {
static let manager = Manager.sharedInstance
}

And after you can use on this way:

Alamofire.manager.request(.GET, videoUrl, parameters: ["foo": "bar"])
            .response { (request, response, data, error) in
                println(request)
                println(response)
                println(error)
        }

Upvotes: 8

Related Questions