Melon 1.0.2

Melon 1.0.2

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最新发布2017年3月
SwiftSwift版本3.0 3.1 3.1
SPM支持SPM

yanzhi维护。



Melon 1.0.2

  • 作者:
  • Caiyanzhi

Melon是一个Swift HTTP网络库。

安装

当前版本仅支持CocoaPods。

pod 'Melon', '~> 1.0.1' 
pod update

要求

  • iOS 7.0+
  • Xcode 8(Swift 3)

简单使用

GET

Melon.GET("https://httpbin.org/get")
            .addHeaders(["a":"a", "b":"b"])
            .addParams(["name": "caiyanzhi", "age":26])
            .onNetworkError({ error in
            }).responseJSON { (jsonObject, response) in
                print("jsonObject : \(jsonObject)" )
        }

POST

 Melon.POST("https://httpbin.org/post")
            .addHeaders(["a":"a", "b":"b"])
            .addParams(["name": "caiyanzhi", "age":26])
            .onNetworkError({ error in
            }).responseJSON { (jsonObject, response) in
                print("jsonObject : \(jsonObject)")
        }

上传

let melon =
        Melon.POST("https://httpbin.org/post")
            .addHeaders(["a":"a", "b":"b"])
            .addParams(["name": "caiyanzhi", "age":26])
            .addFiles([formdata])
            .uploadProgress({ (bytesSent, totalBytesSent, totalBytesExpectedToSend) in
                Melon.Print("totalBytesSent:\(totalBytesSent)")
                Melon.Print("totalBytesExpectedToSend:\(totalBytesExpectedToSend)")
            })
            .onNetworkError({ error in
            }).responseJSON { (jsonObject, response) in
                print("jsonObject : \(jsonObject)")
        }

下载

let melon =
        Melon.Download("https://www.google.co.jp/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png").onNetworkError ({ error in

        }).downloadProgress({ (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in
            print("bytesWritten:\(bytesWritten)")
            print("totalBytesWritten:\(totalBytesWritten)")
            print("totalBytesExpectedToWrite:\(totalBytesExpectedToWrite)")
            print("progress:\(Double(totalBytesWritten) / Double(totalBytesExpectedToWrite))")
        }).responseData { (data, reponse) in
            if let data = data {
                let image = UIImage(data: data)
                print("image: \(image)")
            }
        }

取消

you can use cancel method to cancel request

melon.cancel()
melon.cancel {
    // cancel callback
}

未来将支持

  • 设置SSL固定
  • 队列
  • 其他...

源安装

Clone all files in the Melon directory into your project.