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

Request
Resume 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 Destination

let 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开源项目及介绍的更多相关文章

  1. 关于h5中的fetch方法解读(小结)

    这篇文章主要介绍了关于h5中的fetch方法解读(小结),fetch身为H5中的一个新对象,他的诞生,是为了取代ajax的存在而出现,有兴趣的可以了解一下

  2. ios – Xcode找不到Alamofire,错误:没有这样的模块’Alamofire’

    我正在尝试按照github(https://github.com/Alamofire/Alamofire#cocoapods)指令将Alamofire包含在我的Swift项目中.我创建了一个新项目,导航到项目目录并运行此命令sudogeminstallcocoapods.然后我面临以下错误:搜索后我设法通过运行此命令安装cocoapodssudogeminstall-n/usr/local/bin

  3. ios – 使用NSURLSession获取JSON数据

    我试图从谷歌距离api使用NSURLSession获取数据,但如下所示,当我打印响应和数据时,我得到的结果为NULL.可能是什么问题?

  4. ios – 无法识别的选择器发送到实例NSTimer Swift

    解决方法让updateTime成为一个类方法.如果它是在一个纯粹的Swift类中,你需要在@objc前面说明该方法的声明,如:

  5. ios – bug编译alamofire – 未知选项字符`X’: – Xlinker

    尝试使用cocoapods将alamofire添加到项目中.Xcode版本:6.1.1版Podfile:这是错误:解决方法通过升级到Cocoapods0.36beta解决了这个问题.我也不得不删除旧版本.

  6. ios – “没有这样的模块’Alamofire’”将无法识别框架

    我正在尝试使用Swift将Alamofire添加到一个新的XCode项目中.我觉得我已经尝试了一切.每次我尝试添加进口Alamofire我得到“没有这样的模块”.我已按照https://github.com/Alamofire/Alamofire所述尝试安装,我尝试先手动完成,然后是Carthage和Cocoapods,但结果相同.我已经尝试删除DerivedData文件夹并重建项目,没有任何运气

  7. xcode – tvos:Alamofire框架的iTunesConnect验证失败:不包含bitcode

    解决方法我想你是在项目设置中用appletvsimulator提交Framework.检查此链接Carthageissue

  8. ios – 错误域= com.alamofire.error.serialization.response代码= -1011“请求失败:禁止

    任何人都可以帮我解决以下错误–>在AFNetworking2.5中使用“删除”方法时出错解决方法我发现,如果我的手机时钟不同步……它不允许我更新…也许检查你的手机设置到正确的时间“自动区”,看看是否有效…

  9. iOS网页/原生应用Facebook登录弹出 – 失败?

    如果我重新启动app/web-app,用户将自动登录,并重定向到成功页面.我认为是导致问题的原因当您在Firefox/Chrome/Safari浏览器中运行网页时,Facebook登录对话框会弹出一个弹出窗口或另一个选项卡.我相信这是这个弹出页面的一个问题,以及当成功登录时Javascript如何与自身通信.window.close的东西没有返回的根页面…失败的解决方法由于应用程序挂在前面提到的URL上,我决定在shouldStartLoadWithRequest(…)中添加if语句以强制UIWebvie

  10. ios – 类型推断(自动类型检测)如何在swift中工作?

    LLVM如何检测变量是一个字符串?

随机推荐

  1. Swift UITextField,UITextView,UISegmentedControl,UISwitch

    下面我们通过一个demo来简单的实现下这些控件的功能.首先,我们拖将这几个控件拖到storyboard,并关联上相应的属性和动作.如图:关联上属性和动作后,看看实现的代码:

  2. swift UISlider,UIStepper

    我们用两个label来显示slider和stepper的值.再用张图片来显示改变stepper值的效果.首先,这三个控件需要全局变量声明如下然后,我们对所有的控件做个简单的布局:最后,当slider的值改变时,我们用一个label来显示值的变化,同样,用另一个label来显示stepper值的变化,并改变图片的大小:实现效果如下:

  3. preferredFontForTextStyle字体设置之更改

    即:

  4. Swift没有异常处理,遇到功能性错误怎么办?

    本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请发送邮件至dio@foxmail.com举报,一经查实,本站将立刻删除。

  5. 字典实战和UIKit初探

    ios中数组和字典的应用Applicationschedule类别子项类别名称优先级数据包contactsentertainment接触UIKit学习用Swift调用CocoaTouchimportUIKitletcolors=[]varbackView=UIView(frame:CGRectMake(0.0,0.0,320.0,CGFloat(colors.count*50)))backView

  6. swift语言IOS8开发战记21 Core Data2

    上一话中我们简单地介绍了一些coredata的基本知识,这一话我们通过编程来实现coredata的使用。还记得我们在coredata中定义的那个Model么,上面这段代码会加载这个Model。定义完方法之后,我们对coredata的准备都已经完成了。最后强调一点,coredata并不是数据库,它只是一个框架,协助我们进行数据库操作,它并不关心我们把数据存到哪里。

  7. swift语言IOS8开发战记22 Core Data3

    上一话我们定义了与coredata有关的变量和方法,做足了准备工作,这一话我们来试试能不能成功。首先打开上一话中生成的Info类,在其中引用头文件的地方添加一个@objc,不然后面会报错,我也不知道为什么。

  8. swift实战小程序1天气预报

    在有一定swift基础的情况下,让我们来做一些小程序练练手,今天来试试做一个简单地天气预报。然后在btnpressed方法中依旧增加loadWeather方法.在loadWeather方法中加上信息的显示语句:运行一下看看效果,如图:虽然显示出来了,但是我们的text是可编辑状态的,在storyboard中勾选Editable,再次运行:大功告成,而且现在每次单击按钮,就会重新请求天气情况,大家也来试试吧。

  9. 【iOS学习01】swift ? and !  的学习

    如果不初始化就会报错。

  10. swift语言IOS8开发战记23 Core Data4

    接着我们需要把我们的Rest类变成一个被coredata管理的类,点开Rest类,作如下修改:关键字@NSManaged的作用是与实体中对应的属性通信,BinaryData对应的类型是NSData,CoreData没有布尔属性,只能用0和1来区分。进行如下操作,输入类名:建立好之后因为我们之前写的代码有些地方并不适用于coredata,所以编译器会报错,现在来一一解决。

返回
顶部