Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored All APIs for Swift 3 #1385

Merged
merged 12 commits into from Aug 10, 2016
Merged

Conversation

cnoon
Copy link
Member

@cnoon cnoon commented Aug 8, 2016

The goal of this PR is to refactor ALL APIs used in the framework and test target source code to align with the Swift 3 API design guidelines.

The codebase has also been reorganized to make it easier to subclass the SessionManager, SessionDelegate and Request by eliminating excessive use of extensions by splitting core functionality up by feature.

The new top-level APIs now can be used as follows:

// Data Requests
Alamofire.request("https://httpbin.org/get", withMethod: .get, parameters: ["foo": "bar"])
Alamofire.request(urlRequest)

// Download Requests
Alamofire.download("https://httpbin.org/get", to: destination, withMethod: .get)
Alamofire.download(urlRequest, to: destination)
Alamofire.download(resourceWithin: resumeData, to: destination)

// Upload Requests
Alamofire.upload(imageURL, to: "https://httpbin.org/", withMethod: .post, headers: headers)
Alamofire.upload(data, to: urlString, withMethod: .post, headers: headers)
Alamofire.upload(imageStream, to: urlString, withMethod: .post)

Alamofire.upload(
    multipartFormData: { multipartFormData in
        multipartFormData.append(uploadData, withName: "upload_data")
        formData = multipartFormData
    },
    to: urlString,
    withMethod: .post,
    encodingCompletion: { result in
        switch result {
        case .success(let upload, _, _):
            upload.responseJSON { response in
                debugPrint(response)
            }
        case .failure:
            debugPrint(result)
        }
    }
)

There are also several refactored classes, structs and enums including:

  • Method is now HTTPMethod in ParameterEncoding.swift
  • Manager is now SessionManager in SessionManager.swift
  • Manager.sharedInstance is now SessionManager.default in SessionManager.swift
  • Manager.SessionDelegate is now SessionDelegate in SessionDelegate.swift
  • Request.TaskDelegate is now TaskDelegate in TaskDelegate.swift
  • Request.DataTaskDelegate is now `DataTaskDelegate in TaskDelegate.swift
  • Request.DownloadTaskDelegate is now `DownloadTaskDelegate in TaskDelegate.swift
  • Request.UploadTaskDelegate is now UploadTaskDelegate in TaskDelegate.swift

I've also updates all the public docstrings to use the new Swift 3 formatting syntax. I fixed several issues within the documentation and updated them to all match the new APIs.

The diff here is absolutely horrendous. I would suggest anyone looking to review this pull the branch and look at the changes directly in Xcode.

// MARK: - Data Request

/// Creates a data `Request` using the default session manager instance to retrieve the contents of the specified
/// `method`, `urlString`, `parameters`, `encoding` and `headers`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the order of method and urlString need to be switched here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! Addressed in 2a6ccac.

@cnoon
Copy link
Member Author

cnoon commented Aug 10, 2016

Thanks for the review @jshier. I'm going to go ahead and merge this then repoint the piggy backed PR to the swift3 branch.

@cnoon cnoon merged commit aebd1d4 into swift3 Aug 10, 2016
@cnoon cnoon removed the in progress label Aug 10, 2016
@cnoon cnoon deleted the feature/refactoring-apis-for-swift-3 branch August 29, 2016 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants