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

  1. public enum Method: String {
  2. case OPTIONS, GET, HEAD, POST, PUT, PATCH, DELETE, TRACE, CONNECT
  3. }
  4. ---------------------------
  5. Alamofire.request(.POST, "https://httpbin.org/post")
  6. Alamofire.request(.PUT, "https://httpbin.org/put")
  7. Alamofire.request(.DELETE, "https://httpbin.org/delete")
  • GET Request With URL-Encoded Parameters
  1. Alamofire.request(.GET, "https://httpbin.org/get", parameters: ["foo": "bar"])
  2. // https://httpbin.org/get?foo=bar
  • POST Request With URL-Encoded Parameters
  1. let parameters = [
  2. "foo": "bar",
  3. "baz": ["a", 1],
  4. "qux": [
  5. "x": 1,
  6. "y": 2,
  7. "z": 3
  8. ]
  9. ]
  10. Alamofire.request(.POST, "https://httpbin.org/post", parameters: parameters)
  11. // HTTP body: foo=bar&baz[]=a&baz[]=1&qux[x]=1&qux[y]=2&qux[z]=3
  • POST Request with JSON-encoded Parameters
  1. let parameters = [
  2. "foo": [1,2,3],
  3. "bar": [
  4. "baz": "qux"
  5. ]
  6. ]
  7. Alamofire.request(.POST, "https://httpbin.org/post", parameters: parameters, encoding: .JSON)
  8. // HTTP body: {"foo": [1, 2, 3], "bar": {"baz": "qux"}}
  • HTTP Headers
  1. let headers = [
  2. "Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==",
  3. "Accept": "application/json"
  4. ]
  5. Alamofire.request(.GET, "https://httpbin.org/get", headers: headers)
  6. .responseJSON { response in
  7. debugPrint(response)
  8. }

上传upload:

  • Supported Upload Types
  1. File
  2. Data
  3. Stream
  4. MultipartFormData
  • Uploading a File
  1. let fileURL = NSBundle.mainBundle().URLForResource("Default", withExtension: "png")
  2. Alamofire.upload(.POST, "https://httpbin.org/post", file: fileURL)
  • Uploading with Progress
  1. Alamofire.upload(.POST, "https://httpbin.org/post", file: fileURL)
  2. .progress { bytesWritten, totalBytesWritten, totalBytesExpectedToWrite in
  3. print(totalBytesWritten)
  4. // This closure is NOT called on the main queue for performance
  5. // reasons. To update your ui, dispatch to the main queue.
  6. dispatch_async(dispatch_get_main_queue()) {
  7. print("Total bytes written on main queue: \(totalBytesWritten)")
  8. }
  9. }
  10. .validate()
  11. .responseJSON { response in
  12. debugPrint(response)
  13. }
  • Uploading MultipartFormData
  1. Alamofire.upload(
  2. .POST,
  3. "https://httpbin.org/post",
  4. multipartFormData: { multipartFormData in
  5. multipartFormData.appendBodyPart(fileURL: unicornImageURL, name: "unicorn")
  6. multipartFormData.appendBodyPart(fileURL: rainbowImageURL, name: "rainbow")
  7. },
  8. encodingCompletion: { encodingResult in
  9. switch encodingResult {
  10. case .Success(let upload, _, _):
  11. upload.responseJSON { response in
  12. debugPrint(response)
  13. }
  14. case .Failure(let encodingError):
  15. print(encodingError)
  16. }
  17. }
  18. )

下载Downloading

Supported Download Types

  1. Request
  2. Resume Data
  • Downloading a File
  1. Alamofire.download(.GET, "https://httpbin.org/stream/100") { temporaryURL, response in
  2. let fileManager = NSFileManager.defaultManager()
  3. let directoryURL = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
  4. let pathComponent = response.suggestedFilename
  5. return directoryURL.URLByAppendingPathComponent(pathComponent!)
  6. }
  7. 使用默认的下载的目录:Using the Default Download Destination
  8. let destination = Alamofire.Request.suggestedDownloadDestination(directory: .DocumentDirectory, domain: .UserDomainMask)
  9. Alamofire.download(.GET, "https://httpbin.org/stream/100", destination: destination)
  • Downloading a File w/Progress
  1. Alamofire.download(.GET, "https://httpbin.org/stream/100", destination: destination)
  2. .progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
  3. print(totalBytesRead)
  4. // This closure is NOT called on the main queue for performance
  5. // reasons. To update your ui, dispatch to the main queue.
  6. dispatch_async(dispatch_get_main_queue()) {
  7. print("Total bytes read on main queue: \(totalBytesRead)")
  8. }
  9. }
  10. .response { _, _, _, error in
  11. if let error = error {
  12. print("Failed with error: \(error)")
  13. } else {
  14. print("Downloaded file successfully")
  15. }
  16. }
  • Accessing Resume Data for Failed Downloads访问下载失败的恢复数据
  1. Alamofire.download(.GET, "https://httpbin.org/stream/100", destination: destination)
  2. .response { _, _, data, _ in
  3. if let
  4. data = data,
  5. resumeDataString = NSString(data: data, encoding: NSUTF8StringEncoding)
  6. {
  7. print("Resume Data: \(resumeDataString)")
  8. } else {
  9. print("Resume Data was empty")
  10. }
  11. }
  1. The data parameter is automatically populated with the resumeData if available.数据参数自动填充resumeData如果可用。
  1. let download = Alamofire.download(.GET, "https://httpbin.org/stream/100", destination: destination)
  2. download.response { _, _, _, _ in
  3. if let
  4. resumeData = download.resumeData,
  5. resumeDataString = NSString(data: resumeData, encoding: NSUTF8StringEncoding)
  6. {
  7. print("Resume Data: \(resumeDataString)")
  8. } else {
  9. print("Resume Data was empty")
  10. }
  11. }

十款不容错过的Swift iOS开源项目及介绍的更多相关文章

  1. iOS开源项目周报0413

    由OpenDigg 出品的iOS开源项目周报第十六期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. glidin ...

  2. iOS开源项目周报0406

    由OpenDigg 出品的iOS开源项目周报第十五期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. Tangra ...

  3. iOS开源项目周报0330

    由OpenDigg 出品的iOS开源项目周报第十四期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. FengNi ...

  4. iOS开源项目周报0316

    由OpenDigg 出品的iOS开源项目周报第十二期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等.GodEye  ...

  5. iOS开源项目周报0309

    由OpenDigg 出品的iOS开源项目周报第十期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等.LazyScro ...

  6. iOS开源项目周报0105

    由OpenDigg 出品的iOS开源项目周报第四期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开发方面的开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. He ...

  7. iOS开源项目周报1229

    由OpenDigg 出品的iOS开源项目周报第三期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开发方面的开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. Ma ...

  8. iOS开源项目周报1222

    由OpenDigg 出品的iOS开源项目周报第二期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开发方面的开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. io ...

  9. iOS开源项目周报1215

    由OpenDigg 出品的iOS开源项目周报第一期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开发方面的开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. PY ...

随机推荐

  1. 洛谷P2402 奶牛隐藏(网络流,二分答案,Floyd)

    洛谷题目传送门 了解网络流和dinic算法请点这里(感谢SYCstudio) 题目 题目背景 这本是一个非常简单的问题,然而奶牛们由于下雨已经非常混乱,无法完成这一计算,于是这个任务就交给了你.(奶牛 ...

  2. 【BZOJ4650】【NOI2016】优秀的拆分(后缀数组)

    [BZOJ4650][NOI2016]优秀的拆分(后缀数组) 题面 BZOJ Uoj 题解 如果我们知道以某个位置为开始/结尾的\(AA\)串的个数 那就直接做一下乘法就好 这个怎么求? 枚举一个位置 ...

  3. [HAOI2011]problem a

    题目大意: 网址:https://www.luogu.org/problemnew/show/2519 大意: 一次考试共有\(n\)个人参加, 第\(i\)个人说:"有\(a_i\)个人分 ...

  4. mac 配置虚拟主机

    http://www.upwqy.com/details/4.html 编辑httpd.conf文件,输入命令: vim /etc/apache2/httpd.conf 编辑httpd-vhosts. ...

  5. c# ffmpeg视频转换【转载】

    c#  ffmpeg视频转换 什么是ffmpeg,它有什么作用呢,怎么可以使用它呢,带着问题去找答案吧!先参考百度百科把,我觉得它很强大无奇不有,为了方便大家我就把链接提供了! http://baik ...

  6. To Fill or Not to Fill (贪心)

    转自:https://www.cnblogs.com/XBWer/p/3866486.html With highways available, driving a car from Hangzhou ...

  7. android使用JSON数据和服务器进行交互

    //点击按钮发送反馈信息给服务端,成功则进入优惠券界面 Button upload = (Button) findViewById(R.id.upload); final String finalLa ...

  8. ssh框架中struts.xml 的配置参数详解

    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "- ...

  9. Lintcode245 Subtree solution 题解

    [题目描述] You have two every large binary trees:T1, with millions of nodes, and T2, with hundreds of no ...

  10. Oracle GoldenGate实现数据库同步

    前言:最近刚好在弄数据库同步,网上查了些资料再加上自己整理了一些,做个分享! 一.GoldenGate的安装 1.安装包准备 数据库版本:Oracle Database 11g Release 2(1 ...