Importing Alamofire in Project that targets iOS 7

大憨熊 提交于 2019-12-03 07:31:25

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)
        }

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+

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!