十款不容错过的Swift iOS开源项目及介绍

十款不容错过的Swift iOS开源项目及介绍,第1张

概述1.十款不容错过的Swift iOS开源项目. http://www.csdn.net/article/2014-10-16/2822083-swift-ios-open-source-projects 2.缓存框架 Haneke: Haneke是一款使用Swift语言编写的,轻量级的iOS通用缓存。它为UIImage、NSData、JSON和String提供记忆和LRU磁盘缓存或其他像数据可以读 1.十款不容错过的Swift iOS开源项目.

http://www.csdn.net/article/2014-10-16/2822083-swift-ios-open-source-projects

2.缓存框架 Haneke:

Haneke是一款使用Swift语言编写的,轻量级的iOS通用缓存。它为UIImage、NSData、JsON和String提供记忆和LRU磁盘缓存或其他像数据可以读取或写入的任何其他类型。特别地是,Haneke更擅长处理图像。使用要求:iOS 8.0+、Xcode 6.0。

https://github.com/Haneke/HanekeSwift

3.Alamofire网络库基础教程:

http://www.jianshu.com/p/f1208b5e42d9

http://www.jianshu.com/p/77a86824fa0f

github地址:https://github.com/Alamofire/Alamofire

使用:
- http Methods

public enum Method: String {    case OPTIONS,GET,head,POST,PUT,PATCH,DELETE,TRACE,CONNECT}---------------------------Alamofire.request(.POST,"https://httpbin.org/post")Alamofire.request(.PUT,"https://httpbin.org/put")Alamofire.request(.DELETE,"https://httpbin.org/delete")
GET Request With URL-Encoded Parameters
Alamofire.request(.GET,"https://httpbin.org/get",parameters: ["foo": "bar"])// https://httpbin.org/get?foo=bar
POST Request With URL-Encoded Parameters
let parameters = [    "foo": "bar","baz": ["a",1],"qux": [        "x": 1,"y": 2,"z": 3    ]]Alamofire.request(.POST,"https://httpbin.org/post",parameters: parameters)// http body: foo=bar&baz[]=a&baz[]=1&qux[x]=1&qux[y]=2&qux[z]=3
POST Request with JsON-encoded Parameters
let parameters = [    "foo": [1,2,3],"bar": [        "baz": "qux"    ]]Alamofire.request(.POST,parameters: parameters,enCoding: .JsON)// http body: {"foo": [1,"bar": {"baz": "qux"}}
http headers
let headers = [    "Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==","Accept": "application/Json"]Alamofire.request(.GET,headers: headers)         .responseJsON { response in             deBUGPrint(response)         }
上传upload: Supported Upload Types
file    Data    Stream    MultipartFormData
Uploading a file
let fileURL = NSBundle.mainBundle().URLForResource("Default",withExtension: "png")Alamofire.upload(.POST,file: fileURL)
Uploading with Progress
Alamofire.upload(.POST,file: fileURL)         .progress { bytesWritten,totalBytesWritten,totalBytesExpectedToWrite in             print(totalBytesWritten)             // This closure is NOT called on the main queue for performance             // reasons. To update your ui,dispatch to the main queue.             dispatch_async(dispatch_get_main_queue()) {                 print("Total bytes written on main queue: \(totalBytesWritten)")             }         }         .valIDate()         .responseJsON { response in             deBUGPrint(response)         }
Uploading MultipartFormData
Alamofire.upload(    .POST,multipartFormData: { multipartFormData in        multipartFormData.appendBodyPart(fileURL: unicornImageURL,name: "unicorn")        multipartFormData.appendBodyPart(fileURL: rainbowImageURL,name: "rainbow")    },enCodingCompletion: { enCodingResult in        switch enCodingResult {        case .Success(let upload,_,_):            upload.responseJsON { response in                deBUGPrint(response)            }        case .Failure(let enCodingError):            print(enCodingError)        }    })
下载Downloading

Supported Download Types

RequestResume Data
Downloading a file
Alamofire.download(.GET,"https://httpbin.org/stream/100") { temporaryURL,response in    let fileManager = NSfileManager.defaultManager()    let directoryURL = fileManager.URLsForDirectory(.documentDirectory,inDomains: .UserDomainMask)[0]    let pathComponent = response.suggestedfilename    return directoryURL.URLByAppendingPathComponent(pathComponent!)}使用默认的下载的目录:Using the Default Download Destinationlet destination = Alamofire.Request.suggestedDownloadDestination(directory: .documentDirectory,domain: .UserDomainMask)Alamofire.download(.GET,"https://httpbin.org/stream/100",destination: destination)
Downloading a file w/Progress
Alamofire.download(.GET,destination: destination)         .progress { bytesRead,totalBytesRead,totalBytesExpectedToRead in             print(totalBytesRead)             // This closure is NOT called on the main queue for performance             // reasons. To update your ui,dispatch to the main queue.             dispatch_async(dispatch_get_main_queue()) {                 print("Total bytes read on main queue: \(totalBytesRead)")             }         }         .response { _,error in             if let error = error {                 print("Failed with error: \(error)")             } else {                 print("Downloaded file successfully")             }         }
Accessing Resume Data for Failed Downloads访问下载失败的恢复数据
Alamofire.download(.GET,destination: destination)         .response { _,data,_ in             if let                 data = data,                 resumeDataString = Nsstring(data: data,enCoding: NSUTF8StringEnCoding)             {                 print("Resume Data: \(resumeDataString)")             } else {                 print("Resume Data was empty")             }         }
The data parameter is automatically populated with the resumeData if available.数据参数自动填充resumeData如果可用。
let download = Alamofire.download(.GET,destination: destination)download.response { _,_ in    if let        resumeData = download.resumeData,resumeDataString = Nsstring(data: resumeData,enCoding: NSUTF8StringEnCoding)    {        print("Resume Data: \(resumeDataString)")    } else {        print("Resume Data was empty")    }}
总结

以上是内存溢出为你收集整理的十款不容错过的Swift iOS开源项目及介绍全部内容,希望文章能够帮你解决十款不容错过的Swift iOS开源项目及介绍所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1074582.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存