Latest 0.4.0
Homepage https://github.com/Anyeler/ALNetWorkingSwift
License MIT
Platforms ios 8.0, requires ARC
Dependencies Alamofire, HandyJSON
Authors

ALNetWorkingSwift is mainly provided for internal Swift projects within the company. So far, network request-related operations have been integrated, including the data mapping module.

CI Status
Version
License
Platform

中文文档

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS 8.0+
  • Xcode 9.3+
  • Swift 4.1+

Installation

ALNetWorkingSwift is available through CocoaPods. To install
it, simply add the following line to your Podfile:

platform :ios, '8.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'ALNetWorkingSwift'
    # You can also load only core modules:
    # pod 'ALNetWorkingSwift/Core'
end

Basic usage of core modules

Making request

You can invoke the method to initiate a common network request:

ALHTTPRequestOperationManager.default.requestBase(httpMethod: .get, url: "https://www.baidu.com", urlEncoding: TURLEncoding.default, parameter: nil) { (response) in        
    switch response.result {
    case .success(let res):
        print(res)
    case .failure(let err):
        print(err)
    }
}

You can also call the following methods to upload data:

ALHTTPRequestOperationManager.default.uploadBase(url: "https://www.baidu.com", multipartFormData: { (formData) in
    // The assembly to upload data
}) { (result) in
    switch result {
    case .success(let request, let streamingFromDisk, let streamFileURL):
        print(request)
        print(streamingFromDisk)
        print(streamFileURL ?? "")
    case .failure(let err):
        print(err)
    }
}

Advanced usage

You can also re-encapsulate both approaches to meet your business requirements.

Configuration

To conform to ALCommonConfigProtocol, a struct need to implement Some properties and methods:

public struct HTTPConfig: ALCommonConfigProtocol {

    public var kHttpUserAgent: String = ""

    init() {

    }

    public func getHeader(dictHeader: [String: String]? = nil) -> [String: String] {
        var header: [String:String] = [String: String]()
        if dictHeader != nil {
            header.merge(dictHeader!) { (_, new) in new }
        }
        return header
    }

    public func getContentType(contentType: Set<String>? = nil) -> Set<String> {
        var content: Set<String> = Set<String>()
        contentType?.forEach({ (ele) in
            content.insert(ele)
        })
        return content
    }
}

Then, Call this method:

ALHTTPRequestOperationManager.default.httpConfig = HTTPConfig()

Author

Anyeler, [email protected]

License

ALNetWorkingSwift is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "ALNetWorkingSwift",
    "version": "0.4.0",
    "summary": "u5229u7528Alamofireu8fdbu884cu518du5ea6u5c01u88c5u7f51u7edcu5e93",
    "description": "u5229u7528Alamofireu548cHandyJSONu8fdbu884cu518du5ea6u5c01u88c5uff0cu4ee5u9002u5408u65e5u5e38u9700u6c42",
    "homepage": "https://github.com/Anyeler/ALNetWorkingSwift",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Anyeler": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Anyeler/ALNetWorkingSwift.git",
        "tag": "0.4.0"
    },
    "module_name": "ALNetWorking",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "ALNetWorkingSwift/Classes/*.swift",
    "requires_arc": true,
    "dependencies": {
        "Alamofire": [
            "4.7.3"
        ],
        "HandyJSON": [
            "4.2.0"
        ]
    },
    "subspecs": [
        {
            "name": "Core",
            "source_files": "ALNetWorkingSwift/Classes/Core/*.swift"
        }
    ]
}

Pin It on Pinterest

Share This