码迷,mamicode.com
首页 > 编程语言 > 详细

swift使用ASIHttpRequest

时间:2015-02-02 23:18:40      阅读:411      评论:0      收藏:0      [点我收藏+]

标签:

  1. 添加第三方库ASIHttpRequest
  2. 添加SystemConfiguration.framework, MobileCoreServices.framework,CoreGraphics.framework和libz.1.2.3.dylib类库
  3. 在Build Phases --> Compile Source 中将.m文件的Compiler Flags添加 -fno-objc-arc标识
  4. 在swift和objective-c的桥接文件中插入 #import "ASIHTTPRequest.h"
  5. 编写访问后台的代码

class ServerManager: NSObject, ASIHTTPRequestDelegate{
    
     var server = "http://192.168.0.101:3001"
    
    func getMagazineList()->NSDictionary?{
        var url = NSURL(string: NSString(format: "%@/magazine/list", server))
        var request = ASIHTTPRequest(URL: url)
        request.startSynchronous()
        var requestError = request.error
        var requestData: NSDictionary?
        if(requestError == nil){
            requestData = request.responseString().objectFromJSONString() as? NSDictionary
        }else{
            println("\(requestError)")
        }
        return requestData
    }
    
    func getMagazine() -> NSDictionary?{
        var url =  NSURL(string: NSString(format: "%@/magazine/info", server))
        var request = ASIHTTPRequest(URL: url)
        request.startSynchronous()
        var requestError = request.error
        var requestData:NSDictionary?
        if(requestError == nil){
            requestData = request.responseString().objectFromJSONString() as? NSDictionary
        }else{
            println("\(requestError)")
        }
       return requestData
      
    }
}



swift使用ASIHttpRequest

标签:

原文地址:http://blog.csdn.net/u011550635/article/details/43412369

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!