├── .gitignore ├── LICENSE ├── README.md ├── STNetWork ├── STNetWork.swift ├── STNetWorkDownloadManager.swift ├── STNetWorkManager.swift ├── STNetWorkRequest.swift ├── STNetWorkResponse.swift └── STNetWorkUpLoadFileManager.swift ├── STNetWorkDemo ├── AppDelegate.swift ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── ViewController.swift └── mage-gnome01-large.jpg ├── STNetWorkDemoTests ├── Info.plist └── StanTests.swift ├── STNetworking.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata └── pheasant-729491_640.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | # Node.js modules 2 | node_modules/* 3 | 4 | # Compiled Python files 5 | *.pyc 6 | 7 | # Folder view configuration files 8 | .DS_Store 9 | Desktop.ini 10 | 11 | # Thumbnail cache files 12 | ._* 13 | Thumbs.db 14 | 15 | # Files that might appear on external disks 16 | .Spotlight-V100 17 | .Trashes 18 | 19 | # Exclude the Podspecs 20 | Pods/* 21 | # Podfile.lock should not be ignored. 22 | # See also https://github.com/thoughtbot/liftoff/issues/30 23 | # Podfile.lock 24 | 25 | # Exclude any PSD/AI source 26 | #*.psd 27 | #*.ai 28 | 29 | # Exclude generated files 30 | VersionX-revision.h 31 | 32 | # Exclude the build products 33 | build/* 34 | build.output 35 | pkg/* 36 | *.o 37 | 38 | # Exclude temp nibs and swap files 39 | *~.nib 40 | *.swp 41 | *~ 42 | 43 | # Sparkle distribution Private Key (Don't check me in!) 44 | dsa_priv.pem 45 | 46 | # Exclude user-specific XCode 3 and 4 files 47 | *.mode1 48 | *.mode1v3 49 | *.mode2v3 50 | *.perspective 51 | *.perspectivev3 52 | *.pbxuser 53 | *.xcuserdatad 54 | *.xccheckout 55 | xcuserdata 56 | profile 57 | DerivedData 58 | 59 | # Exclude ReleaseNotes 60 | RELEASENOTES 61 | RELEASENOTES.* 62 | release_notes 63 | release_notes.* 64 | 65 | # Other source repository archive directories (protects when importing) 66 | .hg 67 | .svn 68 | CVS 69 | 70 | # idea project files 71 | .idea 72 | *.hmap 73 | 74 | # twistd pid files 75 | twistd.pid 76 | 77 | # Rails 78 | # Ignore bundler config. 79 | .bundle 80 | 81 | # Ignore the default SQLite database. 82 | db/*.sqlite3 83 | db/*.sqlite3-journal 84 | 85 | # Ignore all logfiles and templates. 86 | log/*.log 87 | tmp 88 | 89 | # Ignore vendor cache 90 | vendor/cache 91 | Pods/ 92 | libWeChatSDK.a 93 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | STNetWork 2 | https://github.com/lcepy/STNetWork 3 | 4 | Copyright (C) 2015 http://lcepy.github.io/ 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## STNetwork 2 | 3 | > Tag 0.0.1 4 | 5 | ![](https://img.shields.io/jenkins/s/https/jenkins.qa.ubuntu.com/precise-desktop-amd64_default.svg) 6 | ![](https://img.shields.io/github/license/mashape/apistatus.svg) 7 | ![](https://camo.githubusercontent.com/770175f6c01d89c84a020706126a9e6399ff76c4/68747470733a2f2f696d672e736869656c64732e696f2f636f636f61706f64732f702f4b696e676669736865722e7376673f7374796c653d666c6174) 8 | 9 | STNetwork is an HTTP networking library written in Swift 10 | 11 | ## Requirements 12 | 13 | * iOS 7.0+ 14 | * Xcode 6.3 15 | 16 | ## HTTP Method 17 | 18 | public enum HTTPMETHOD:String{ 19 | case DELETE = "DELETE" 20 | case GET = "GET" 21 | case HEAD = "HEAD" 22 | case OPTIONS = "OPTIONS" 23 | case PATCH = "PATCH" 24 | case POST = "POST" 25 | case PUT = "PUT" 26 | } 27 | 28 | These values can be passed as the first argument of the STNetwork.request method: 29 | 30 | STNetwork.request(HTTPMETHOD.GET.rawValue, url:"http://lcepy.github.io") 31 | 32 | STNetwork.request(HTTPMETHOD.POST.rawValue, url:"http://lcepy.github.io") 33 | 34 | ## File Struct 35 | 36 | public struct STFile{ 37 | let fileName:String! 38 | let fileURL:String? 39 | let fileData:NSData? 40 | internal init(name:String,url:String?,data:NSData?){ 41 | self.fileName = name 42 | self.fileURL = url 43 | self.fileData = data 44 | } 45 | } 46 | 47 | public struct STFType{ 48 | let fileName:String! 49 | let fileType:String! 50 | internal init(name:String,type:String){ 51 | self.fileName = name 52 | self.fileType = type 53 | } 54 | } 55 | 56 | ## Params 57 | 58 | GET Request With URL-Encoded Params 59 | 60 | var url:String = "http://apis.baidu.com/apistore/aqiservice/aqi" 61 | var citys:Dictionary = Dictionary() 62 | citys["city"] = "北京" 63 | var header:Dictionary = Dictionary() 64 | header["apikey"] = "bce358f5243e78bad9ebd6da21f742d1" 65 | STNetwork.request(HTTPMETHOD.GET.rawValue, url: url, params: citys, header: header, success: { (dataString, data, response) -> Void in 66 | println(dataString) 67 | }) { (error) -> Void in 68 | println(error) 69 | } 70 | 71 | //http://apis.baidu.com/apistore/aqiservice/aqi?city=%E5%8C%97%E4%BA%AC 72 | 73 | POST Request With URL-Encoded Params 74 | 75 | var url = "http://apis.baidu.com/apistore/idlocr/ocr" 76 | var httpArg = "fromdevice=pc&clientip=10.10.10.0&detecttype=LocateRecognize&languagetype=CHN_ENG&imagetype=1&image=/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABMNDxEPDBMREBEWFRMXHTAfHRsbHTsqLSMwRj5KSUU+RENNV29eTVJpU0NEYYRiaXN3fX59S12Jkoh5kW96fXj/2wBDARUWFh0ZHTkfHzl4UERQeHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHj/wAARCAAfACEDAREAAhEBAxEB/8QAGAABAQEBAQAAAAAAAAAAAAAAAAQDBQb/xAAjEAACAgICAgEFAAAAAAAAAAABAgADBBESIRMxBSIyQXGB/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/APawEBAQEBAgy8i8ZTVV3UY6V1eU2XoWDDZB19S646Gz39w9fkKsW1r8Wm2yo1PYis1be0JG9H9QNYCAgc35Cl3yuVuJZl0cB41rZQa32dt2y6OuOiOxo61vsLcVblxaVyXD3hFFjL6La7I/sDWAgICAgICB/9k=" 77 | var header:Dictionary = Dictionary() 78 | header["Content-Type"] = "application/x-www-form-urlencoded" 79 | header["apikey"] = "bce358f5243e78bad9ebd6da21f742d1" 80 | STNetwork.request(HTTPMETHOD.POST.rawValue, url: url, params: ["urlencoded":httpArg], header: header, success: { (dataString, data, response) -> Void in 81 | println(dataString) 82 | }) { (error) -> Void in 83 | println(error) 84 | } 85 | 86 | if you set Header Content-type equal "application/json",then STNetwork used NSJSONSerialization handler your params 87 | 88 | ## STNetworkResponse 89 | 90 | Response with handler 91 | 92 | * getAllResponseHeader 获取所有的头信息(get all response header) 93 | * getResponseHeader 根据key返回一个header值 (return header value -single) 94 | * getStatusCode 返回响应的状态码 (return status code ) 95 | * getAllStorageCookie 获取全局所有的cookie包括共享的cookie (get all storage cookies NSHTTPCookie) 96 | * getAllResponseCookie 获取当前response的cookie(return header Set-Cookie) 97 | * getResponseCookie 根据key返回一个cookie值 (return cookie value -single) 98 | 99 | ## STNetworkRequest 100 | 101 | * setRequestHeader 设置header信息( set your request headers) 102 | * setRequestCookie 设置cookie (set cookie header Set-Cookie) 103 | * setRequestTimeout 设置超时时间 (set request time out) 104 | * static buildParams 拼接URL字符串 105 | * static queryComponents 查询字符串 106 | * static escape 转义 107 | * property STParams 不是文件数据的请用它的set方法 108 | * property STFileParams 文件数据请用它的set方法 109 | 110 | ## Usage 111 | 112 | * request 113 | * upload 114 | * download 115 | * taskupload 116 | 117 | 使用例子 118 | 119 | //普通的GET 请求 120 | 121 | @IBAction func sendGetHttp(sender: UIButton) { 122 | var url:String = "http://lcepy.github.io"; 123 | STNetwork.request(HTTPMETHOD.GET.rawValue, url: url, success: { (dataString, data, response) -> Void in 124 | println(dataString) 125 | }) { (error) -> Void in 126 | println(error) 127 | } 128 | 129 | } 130 | 131 | //带参数的GET 请求 132 | 133 | @IBAction func sendGetParamsHttp(sender: UIButton) { 134 | var url:String = "http://apis.baidu.com/apistore/aqiservice/aqi" 135 | var citys:Dictionary = Dictionary() 136 | citys["city"] = "北京" 137 | var header:Dictionary = Dictionary() 138 | header["apikey"] = "bce358f5243e78bad9ebd6da21f742d1" 139 | STNetwork.request(HTTPMETHOD.GET.rawValue, url: url, params: citys, header: header, success: { (dataString, data, response) -> Void in 140 | println(dataString) 141 | }) { (error) -> Void in 142 | println(error) 143 | } 144 | } 145 | 146 | //POST请求 带参数 147 | 148 | @IBAction func sendPostParamsHttp(sender: UIButton) { 149 | var url = "http://apis.baidu.com/apistore/idlocr/ocr" 150 | var httpArg = "fromdevice=pc&clientip=10.10.10.0&detecttype=LocateRecognize&languagetype=CHN_ENG&imagetype=1&image=/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABMNDxEPDBMREBEWFRMXHTAfHRsbHTsqLSMwRj5KSUU+RENNV29eTVJpU0NEYYRiaXN3fX59S12Jkoh5kW96fXj/2wBDARUWFh0ZHTkfHzl4UERQeHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHj/wAARCAAfACEDAREAAhEBAxEB/8QAGAABAQEBAQAAAAAAAAAAAAAAAAQDBQb/xAAjEAACAgICAgEFAAAAAAAAAAABAgADBBESIRMxBSIyQXGB/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/APawEBAQEBAgy8i8ZTVV3UY6V1eU2XoWDDZB19S646Gz39w9fkKsW1r8Wm2yo1PYis1be0JG9H9QNYCAgc35Cl3yuVuJZl0cB41rZQa32dt2y6OuOiOxo61vsLcVblxaVyXD3hFFjL6La7I/sDWAgICAgICB/9k=" 151 | var header:Dictionary = Dictionary() 152 | header["Content-Type"] = "application/x-www-form-urlencoded" 153 | header["apikey"] = "bce358f5243e78bad9ebd6da21f742d1" 154 | STNetwork.request(HTTPMETHOD.POST.rawValue, url: url, params: ["urlencoded":httpArg], header: header, success: { (dataString, data, response) -> Void in 155 | println(dataString) 156 | }) { (error) -> Void in 157 | println(error) 158 | } 159 | } 160 | 161 | //普通POST请求 162 | 163 | @IBAction func sendPOSTHttp(sender: UIButton) { 164 | var url = "http://apis.baidu.com/apistore/idlocr/ocr" 165 | var header:Dictionary = Dictionary() 166 | header["Content-Type"] = "application/x-www-form-urlencoded" 167 | header["apikey"] = "bce358f5243e78bad9ebd6da21f742d1" 168 | STNetwork.request(HTTPMETHOD.POST.rawValue, url: url, success: { (dataString, data, response) -> Void in 169 | println(dataString) 170 | }) { (error) -> Void in 171 | println(error) 172 | } 173 | 174 | } 175 | 176 | //上传文件 177 | 178 | @IBAction func sendUPLOADFILEHttp(sender: UIButton) { 179 | let url:String = "http://pitayaswift.sinaapp.com/pitaya.php" 180 | //模拟表单提交 181 | let fileType:STFType = STFType(name: "mage-gnome01-large", type: "jpg") 182 | STNetwork.upload(url, type: fileType, success: { (data, response) -> Void in 183 | println(NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments, error: nil)) 184 | }) { (error) -> Void in 185 | println(error) 186 | } 187 | } 188 | 189 | //下载文件 190 | 191 | @IBAction func sendDownloadFile(sender: UIButton) { 192 | var url:String = "http://content.battlenet.com.cn/wow/media/screenshots/screenshot-of-the-day/warlords-of-draenor/warlords-of-draenor-ss0420-large.jpg" 193 | STNetwork.download(url, success: { (url, response) -> Void in 194 | 195 | }) { (error) -> Void in 196 | 197 | } 198 | } 199 | 200 | ## License 201 | 202 | STNetWork is released under the MIT license. See LICENSE for details. 203 | -------------------------------------------------------------------------------- /STNetWork/STNetWork.swift: -------------------------------------------------------------------------------- 1 | // 2 | // STNetWork.swift 3 | // Stan 4 | // 5 | // Created by xiangwenwen on 15/6/2. 6 | // Copyright (c) 2015年 xiangwenwen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | 12 | class STNetwork: NSObject { 13 | 14 | /** 15 | GET|POST 普通的 16 | 17 | :param: method <#method description#> 18 | :param: url <#url description#> 19 | :param: success <#success description#> 20 | :param: error <#error description#> 21 | */ 22 | static func request(method:String,url:String,success:((dataString:NSString!,data:NSData!,response:NSURLResponse!)-> Void)? = nil,error:((error:NSError!)-> Void)? = nil)->Void{ 23 | let manager = STNetworkManager(url: url, method: method,success: success, error: error, STRequest: nil) 24 | manager.fire() 25 | } 26 | 27 | /** 28 | GET|POST 带参数的请求 29 | 30 | :param: method <#method description#> 31 | :param: url <#url description#> 32 | :param: params <#params description#> 33 | :param: success <#success description#> 34 | :param: error <#error description#> 35 | */ 36 | static func request(method:String,url:String,params:Dictionary,success:((dataString:NSString!,data:NSData!,response:NSURLResponse!)-> Void)? = nil,error:((error:NSError!)-> Void)? = nil)->Void{ 37 | var HttpUrl:String! = url 38 | if method == HTTPMETHOD.GET.rawValue{ 39 | HttpUrl = HttpUrl+"?"+STNetworkRequest.buildParams(params) 40 | } 41 | let manager = STNetworkManager(url: HttpUrl, method: method, success: success, error: error, STRequest: nil) 42 | if method != HTTPMETHOD.GET.rawValue{ 43 | manager.STRequest.STParams = params 44 | } 45 | manager.fire() 46 | } 47 | 48 | /** 49 | GET|POST 带参数并且可以设置头 50 | 51 | :param: method <#method description#> 52 | :param: url <#url description#> 53 | :param: params <#params description#> 54 | :param: header <#header description#> 55 | :param: success <#success description#> 56 | :param: error <#error description#> 57 | */ 58 | static func request(method:String,url:String,params:Dictionary,header:Dictionary,success:((dataString:NSString!,data:NSData!,response:NSURLResponse!)-> Void)? = nil,error:((error:NSError!)-> Void)? = nil)->Void{ 59 | var HttpUrl:String! = url 60 | if method == HTTPMETHOD.GET.rawValue{ 61 | HttpUrl = HttpUrl+"?"+STNetworkRequest.buildParams(params) 62 | } 63 | println(HttpUrl) 64 | let manager = STNetworkManager(url: HttpUrl, method: method, success: success, error: error, STRequest: nil) 65 | manager.STRequest.setRequestHeader(header) 66 | if method != HTTPMETHOD.GET.rawValue{ 67 | manager.STRequest.STParams = params 68 | } 69 | manager.fire() 70 | } 71 | 72 | /** 73 | POST模拟表单提交文件 74 | 75 | :param: url <#url description#> 76 | :param: type <#type description#> 77 | :param: success <#success description#> 78 | :param: error <#error description#> 79 | */ 80 | static func upload(url:String,type:STFType,success:((data:NSData!,response:NSURLResponse!)-> Void)? = nil,error:((error:NSError!)-> Void)? = nil)->Void{ 81 | let codeName:String = "file" 82 | let fileUrl:String? = NSBundle.mainBundle().pathForResource(type.fileName, ofType:type.fileType) 83 | if let _fileUrl = fileUrl{ 84 | let manager = STNetworkUpLoadFileManager(url: url, files: nil, success: success, error: error, STRequest: nil) 85 | let file = STFile(name: codeName, url: _fileUrl,data:nil) 86 | let header:Dictionary = ["Content-Type":"multipart/form-data; boundary=\(boundary)"] 87 | manager.STRequest.setRequestHeader(header) 88 | manager.STRequest.STFileParams = [file] 89 | manager.fire() 90 | } 91 | 92 | } 93 | 94 | /** 95 | POST Task 提交文件 96 | 97 | :param: URL <#URL description#> 98 | :param: files <#files description#> 99 | :param: success <#success description#> 100 | :param: error <#error description#> 101 | */ 102 | static func taskupload(URL:String,files:Array,success:(data:NSData!,response:NSURLResponse!)-> Void,error:(error:NSError!)-> Void)-> Void{ 103 | let manager = STNetworkUpLoadFileManager(url: URL,files:files, success: success, error: error, STRequest: nil) 104 | manager.STRequest.HTTPMethod = HTTPMETHOD.GET.rawValue 105 | manager.fire() 106 | } 107 | 108 | /** 109 | 下载 110 | 111 | :param: URL <#URL description#> 112 | :param: success <#success description#> 113 | :param: error <#error description#> 114 | */ 115 | static func download(URL:String,success:(url:NSURL!,response:NSURLResponse!)-> Void,error:(error:NSError!)-> Void)->Void{ 116 | let manager = STNetworkDownloadManager(URL: URL, success: success, error: error, STRequest: nil) 117 | manager.STRequest.HTTPMethod = HTTPMETHOD.GET.rawValue 118 | manager.fire() 119 | } 120 | } 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /STNetWork/STNetWorkDownloadManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // STNetWorkDownloadManager.swift 3 | // STNetWork 4 | // 5 | // Created by xiangwenwen on 15/6/12. 6 | // Copyright (c) 2015年 xiangwenwen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class STNetworkDownloadManager: NSObject { 12 | 13 | let HttpUrl:String! 14 | let success:((url:NSURL!,response:NSURLResponse!)->Void)? 15 | let error:((error:NSError!)->Void)? 16 | var STRequest:STNetworkRequest! 17 | 18 | init(URL:String,success:((url:NSURL!,response:NSURLResponse!)->Void)?,error:((error:NSError!)->Void)?,STRequest:STNetworkRequest?) { 19 | self.HttpUrl = URL 20 | self.success = success 21 | self.error = error 22 | if let _STRequest = STRequest{ 23 | self.STRequest = _STRequest 24 | }else{ 25 | self.STRequest = STNetworkRequest(HttpURL: NSURL(string: self.HttpUrl)!) 26 | } 27 | } 28 | 29 | func fire()->Void{ 30 | let configur = NSURLSessionConfiguration.defaultSessionConfiguration() 31 | let session = NSURLSession(configuration: configur) 32 | let task = session.downloadTaskWithRequest(self.STRequest, completionHandler: { (url, response, error) -> Void in 33 | if error != nil{ 34 | let err = NSError(domain: "\(domain)", code: error.code, userInfo: error.userInfo) 35 | self.error?(error: err) 36 | }else{ 37 | self.success?(url: url, response: response) 38 | } 39 | }) 40 | task.resume() 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /STNetWork/STNetWorkManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // STNetWorkManager.swift 3 | // Stan 4 | // 5 | // Created by xiangwenwen on 15/6/2. 6 | // Copyright (c) 2015年 xiangwenwen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class STNetworkManager: NSObject { 12 | let HTTPMethod:String! 13 | let success:((dataString:NSString!,data:NSData!,response:NSURLResponse!)-> Void)? 14 | let error:((error:NSError!)-> Void)? 15 | 16 | var HTTPUrl:String! 17 | var STRequest:STNetworkRequest! 18 | var task:NSURLSessionTask! 19 | var session:NSURLSession! 20 | 21 | init(url:String,method:String,success:((dataString:NSString!,data:NSData!,response:NSURLResponse!)-> Void)? = nil,error:((error:NSError!)-> Void)? = nil,STRequest:STNetworkRequest?) { 22 | self.HTTPUrl = url 23 | self.HTTPMethod = method 24 | self.error = error 25 | self.success = success 26 | if let _STRequest = STRequest{ 27 | self.STRequest = _STRequest 28 | }else{ 29 | self.STRequest = STNetworkRequest(HttpURL: NSURL(string: self.HTTPUrl)!) 30 | self.STRequest.HTTPMethod = self.HTTPMethod 31 | } 32 | } 33 | 34 | func fire()-> Void{ 35 | println(self.STRequest.allHTTPHeaderFields) 36 | let configur = NSURLSessionConfiguration.defaultSessionConfiguration() 37 | let session = NSURLSession(configuration:configur) 38 | let task = session.dataTaskWithRequest(self.STRequest, completionHandler: { (data, response, error) -> Void in 39 | if error != nil{ 40 | let err = NSError(domain: "\(domain)", code: error.code, userInfo: error.userInfo) 41 | self.error?(error: err) 42 | }else{ 43 | if let HttpResponse = response as? NSHTTPURLResponse{ 44 | let code = HttpResponse.statusCode 45 | if code >= 400{ 46 | self.error?(error: NSError(domain: "\(domain)", code: code, userInfo: error.userInfo)) 47 | }else{ 48 | let responseString:NSString = NSString(data:data, encoding:NSUTF8StringEncoding)! 49 | self.success?(dataString: responseString, data: data, response: response) 50 | } 51 | println("STNetWork HTTP Status: \(code) \(NSHTTPURLResponse.localizedStringForStatusCode(code))") 52 | } 53 | } 54 | }) 55 | task.resume() 56 | } 57 | } -------------------------------------------------------------------------------- /STNetWork/STNetWorkRequest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // STNetWorkRequest.swift 3 | // STNetWork 4 | // 5 | // Created by xiangwenwen on 15/6/12. 6 | // Copyright (c) 2015年 xiangwenwen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public enum HTTPMETHOD:String{ 12 | case DELETE = "DELETE" 13 | case GET = "GET" 14 | case HEAD = "HEAD" 15 | case OPTIONS = "OPTIONS" 16 | case PATCH = "PATCH" 17 | case POST = "POST" 18 | case PUT = "PUT" 19 | } 20 | 21 | let boundary = "WenUGl0YXlh" 22 | let domain = "wen.STNetWork" 23 | 24 | extension String { 25 | var STNSData: NSData { 26 | return self.dataUsingEncoding(NSUTF8StringEncoding)! 27 | } 28 | var STBase64: String! { 29 | let utf8EncodeData: NSData! = self.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true) 30 | let base64EncodingData = utf8EncodeData.base64EncodedStringWithOptions(nil) 31 | return base64EncodingData 32 | } 33 | } 34 | 35 | class STNetworkRequest:NSMutableURLRequest{ 36 | 37 | let STUserAgent: String = { 38 | if let info = NSBundle.mainBundle().infoDictionary { 39 | let executable: AnyObject = info[kCFBundleExecutableKey] ?? "Unknown" 40 | let bundle: AnyObject = info[kCFBundleIdentifierKey] ?? "Unknown" 41 | let version: AnyObject = info[kCFBundleVersionKey] ?? "Unknown" 42 | let os: AnyObject = NSProcessInfo.processInfo().operatingSystemVersionString ?? "Unknown" 43 | var mutableUserAgent = NSMutableString(string: "\(executable)/\(bundle) (\(version); OS \(os))") as CFMutableString 44 | let transform = NSString(string: "Any-Latin; Latin-ASCII; [:^ASCII:] Remove") as CFString 45 | if CFStringTransform(mutableUserAgent, nil, transform, 0) == 1 { 46 | return mutableUserAgent as NSString as! String 47 | } 48 | } 49 | return "STNetWork" 50 | }() 51 | var STParams:Dictionary?{ 52 | get{ 53 | return self._STParams 54 | } 55 | set(newValue){ 56 | self._STParams = newValue 57 | self.HTTPBody = self.setRequestBody() 58 | } 59 | } 60 | private var _STParams:Dictionary? 61 | 62 | var STFileParams:Array?{ 63 | get{ 64 | return self._STFileParams 65 | } 66 | set(newValue){ 67 | self._STFileParams = newValue 68 | self.HTTPBody = self.setRequestFile() 69 | } 70 | } 71 | private var _STFileParams:Array? 72 | 73 | 74 | /** 75 | 便利构造方法(传入一个NSURL) 76 | 77 | :param: HttpURL <#HttpURL description#> 78 | 79 | :returns: <#return value description#> 80 | */ 81 | convenience init(HttpURL:NSURL){ 82 | self.init(HttpURL:HttpURL,cachePolicy:NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData,timeoutInterval:NSTimeInterval(13)) 83 | } 84 | 85 | /** 86 | 便利构造方法(传入一个NSURL,设置超时时间) 87 | 88 | :param: HttpURL <#HttpURL description#> 89 | :param: timeoutInterval <#timeoutInterval description#> 90 | 91 | :returns: <#return value description#> 92 | */ 93 | convenience init(HttpURL:NSURL,timeoutInterval:NSTimeInterval){ 94 | self.init(HttpURL:HttpURL,cachePolicy:NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData,timeoutInterval:timeoutInterval) 95 | } 96 | 97 | /** 98 | 原始的init方法(传入一个NSURL,指定缓存策略,设置超时时间) 99 | 100 | :param: HttpURL <#HttpURL description#> 101 | :param: cachePolicy <#cachePolicy description#> 102 | :param: timeoutInterval <#timeoutInterval description#> 103 | 104 | :returns: <#return value description#> 105 | */ 106 | init(HttpURL:NSURL,cachePolicy:NSURLRequestCachePolicy,timeoutInterval:NSTimeInterval){ 107 | super.init(URL: HttpURL, cachePolicy: cachePolicy, timeoutInterval: timeoutInterval) 108 | self.addValue(self.STUserAgent, forHTTPHeaderField: "User-Agent") 109 | } 110 | 111 | required init(coder aDecoder: NSCoder) { 112 | super.init(coder: aDecoder) 113 | } 114 | 115 | /** 116 | 设置header 117 | 118 | :param: header <#header description#> 119 | */ 120 | func setRequestHeader(header:Dictionary?)-> Void{ 121 | if let Rheader:Dictionary = header{ 122 | for(key,value) in Rheader{ 123 | self.addValue(value as? String, forHTTPHeaderField: key) 124 | } 125 | } 126 | } 127 | 128 | /** 129 | 设置cookie 130 | 131 | :param: cookie <#cookie description#> 132 | */ 133 | func setRequestCookie(cookie:Dictionary?)->Void{ 134 | if let Rcookie:Dictionary = cookie{ 135 | var _cookie:String = "" 136 | for(key,value) in Rcookie{ 137 | _cookie = _cookie+"\(key)=\(value as! String);" 138 | } 139 | self.setRequestHeader(["Set-Cookie":_cookie]) 140 | } 141 | } 142 | 143 | /** 144 | 给当前request 设置超时时间 145 | 146 | :param: timeout <#timeout description#> 147 | */ 148 | func setRequestTimeout(timeout:NSTimeInterval?)-> Void{ 149 | self.timeoutInterval = NSTimeInterval(timeout == nil ? NSTimeInterval(10) : NSTimeInterval(timeout!)) 150 | } 151 | 152 | /** 153 | 拼接URL字符串 154 | 155 | :param: parameters <#parameters description#> 156 | 157 | :returns: <#return value description#> 158 | */ 159 | static func buildParams(parameters: [String: AnyObject]) -> String { 160 | var components: [(String, String)] = [] 161 | for key in sorted(Array(parameters.keys), <) { 162 | let value: AnyObject! = parameters[key] 163 | components += STNetworkRequest.queryComponents(key, value) 164 | } 165 | return join("&", components.map{"\($0)=\($1)"} as [String]) 166 | } 167 | 168 | /** 169 | 查询字符串 170 | 171 | :param: key <#key description#> 172 | :param: value <#value description#> 173 | 174 | :returns: <#return value description#> 175 | */ 176 | static func queryComponents(key: String, _ value: AnyObject) -> [(String, String)] { 177 | var components: [(String, String)] = [] 178 | if let dictionary = value as? [String: AnyObject] { 179 | for (nestedKey, value) in dictionary { 180 | components += queryComponents("\(key)[\(nestedKey)]", value) 181 | } 182 | } else if let array = value as? [AnyObject] { 183 | for value in array { 184 | components += queryComponents("\(key)", value) 185 | } 186 | } else { 187 | components.extend([(STNetworkRequest.escape(key), escape("\(value)"))]) 188 | } 189 | return components 190 | } 191 | 192 | /** 193 | 转义 194 | 195 | :param: string <#string description#> 196 | 197 | :returns: <#return value description#> 198 | */ 199 | static func escape(string: String) -> String { 200 | let legalURLCharactersToBeEscaped: CFStringRef = ":;+!@#$()',*" 201 | return CFURLCreateStringByAddingPercentEscapes(nil, string, nil, legalURLCharactersToBeEscaped, CFStringBuiltInEncodings.UTF8.rawValue) as String 202 | } 203 | 204 | private func setRequestBody()-> NSData{ 205 | var header = self.allHTTPHeaderFields 206 | var body = NSMutableData() 207 | if let contentType:AnyObject = header!["Content-Type"]{ 208 | if String(contentType as! String) == "application/json"{ 209 | if let params = self._STParams{ 210 | println("set Content-Type --- \(contentType)") 211 | return NSJSONSerialization.dataWithJSONObject(self._STParams!, options:NSJSONWritingOptions.allZeros, error: nil)! 212 | } 213 | } 214 | if String(contentType as! String) == "application/x-www-form-urlencoded"{ 215 | if let params = self._STParams{ 216 | println("set Content-Type --- \(contentType)") 217 | var _paramsString:String = "" 218 | for(key,value) in self._STParams!{ 219 | _paramsString = _paramsString+(value as! String) 220 | } 221 | body.appendData(_paramsString.STNSData) 222 | return body 223 | } 224 | } 225 | } 226 | println("set Content-Type --- empty") 227 | if let params = self._STParams{ 228 | body.appendData(STNetworkRequest.buildParams(self._STParams!).STNSData) 229 | return body 230 | }else{ 231 | return body 232 | } 233 | } 234 | 235 | private func setRequestFile()-> NSData{ 236 | var header = self.allHTTPHeaderFields 237 | var body = NSMutableData() 238 | //multipart/form-data 上传所使用的Content-Type 239 | //image/jpg upload task 240 | if let contentType:AnyObject = header!["Content-Type"]{ 241 | println("set Content-Type --- \(contentType)") 242 | }else{ 243 | println("set Content-Type --- empty") 244 | } 245 | for file in self.STFileParams!{ 246 | if file.fileData == nil{ 247 | body.appendData("--\(boundary)\r\n".STNSData) 248 | var _fileURL = NSURL(fileURLWithPath: file.fileURL!)! 249 | body.appendData("Content-Disposition: form-data; name=\"\(file.fileName)\"; filename=\"\(_fileURL.description.lastPathComponent)\"\r\n\r\n".STNSData) 250 | if let fileData = NSData(contentsOfFile: file.fileURL!){ 251 | body.appendData(fileData) 252 | body.appendData("\r\n".STNSData) 253 | } 254 | }else{ 255 | body.appendData(file.fileData!) 256 | } 257 | } 258 | body.appendData("--\(boundary)--\r\n".STNSData) 259 | return body 260 | } 261 | } -------------------------------------------------------------------------------- /STNetWork/STNetWorkResponse.swift: -------------------------------------------------------------------------------- 1 | // 2 | // STNetWorkResponse.swift 3 | // STNetWork 4 | // 5 | // Created by xiangwenwen on 15/6/12. 6 | // Copyright (c) 2015年 xiangwenwen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class STNetworkResponse: NSObject { 12 | var httpResponse:NSHTTPURLResponse? 13 | var response:NSURLResponse? 14 | var responseHeader:Dictionary? 15 | var responseCookie:Dictionary! 16 | init(response:NSURLResponse?) { 17 | self.httpResponse = response as? NSHTTPURLResponse 18 | self.response = response 19 | self.responseHeader = self.httpResponse?.allHeaderFields 20 | super.init() 21 | self.responseCookie = self.getAllResponseCookie() 22 | } 23 | 24 | /** 25 | 获取 response所有的头信息 26 | 27 | :returns: <#return value description#> 28 | */ 29 | func getAllResponseHeader()-> Dictionary?{ 30 | if let responseHeader = self.responseHeader{ 31 | return responseHeader 32 | } 33 | return nil 34 | } 35 | 36 | /** 37 | 获取 response的响应状态 38 | 39 | :returns: <#return value description#> 40 | */ 41 | func getStatusCode()->Int?{ 42 | return self.httpResponse?.statusCode 43 | } 44 | 45 | /** 46 | 根据key返回一个header值 47 | 48 | :param: headerKey <#headerKey description#> 49 | 50 | :returns: <#return value description#> 51 | */ 52 | func getResponseHeader(headerKey:NSObject?)->AnyObject?{ 53 | if let key = headerKey{ 54 | return self.responseHeader![headerKey!] 55 | } 56 | return nil 57 | } 58 | 59 | /** 60 | 获取所有的 cookie (注意,这个方法获取的是全局的) 61 | 62 | :returns: <#return value description#> 63 | */ 64 | func getAllStorageCookie()->Array?{ 65 | var cookieStorage = NSHTTPCookieStorage.sharedHTTPCookieStorage() 66 | if let cookies:Array = cookieStorage.cookies{ 67 | return cookies 68 | } 69 | return nil 70 | } 71 | 72 | /** 73 | 获取当前 response 的所有cookie 74 | 75 | :returns: <#return value description#> 76 | */ 77 | func getAllResponseCookie()->Dictionary?{ 78 | self.responseCookie = [:] 79 | if let cookiesString: NSString = self.responseHeader!["Set-Cookie" as NSObject] as? NSString{ 80 | var cookiesArray:Array = cookiesString.componentsSeparatedByString(";") 81 | for cookiesOne in cookiesArray{ 82 | if let _cookiesOne = cookiesOne as? NSString{ 83 | var _cookiesArray:Array = _cookiesOne.componentsSeparatedByString(",") 84 | for _cookiesString in _cookiesArray{ 85 | if var _value = _cookiesString as? NSString{ 86 | _value = _value.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet()) 87 | var cookie:Array = _value.componentsSeparatedByString("=") 88 | var cookieKey:String = String(cookie[0] as! String) 89 | self.responseCookie[cookieKey as NSObject] = cookie[1] 90 | } 91 | } 92 | }else{ 93 | if var value = cookiesOne as? NSString{ 94 | value = value.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet()) 95 | var cookie:Array = value.componentsSeparatedByString("=") 96 | var cookieKey:String = String(cookie[0] as! String) 97 | self.responseCookie[cookieKey as NSObject] = cookie[1] 98 | } 99 | } 100 | } 101 | return self.responseCookie 102 | } 103 | return nil 104 | } 105 | 106 | /** 107 | 根据key返回一个cookie值 108 | 109 | :param: cookieKey <#cookieKey description#> 110 | 111 | :returns: <#return value description#> 112 | */ 113 | func getResponseCookie(cookieKey:NSObject?)->AnyObject?{ 114 | if let key:NSObject = cookieKey{ 115 | if let value:AnyObject = self.responseCookie?[key]{ 116 | return value 117 | } 118 | return nil 119 | } 120 | return nil 121 | } 122 | } -------------------------------------------------------------------------------- /STNetWork/STNetWorkUpLoadFileManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // STNetWorkUpLoadFileManager.swift 3 | // STNetWork 4 | // 5 | // Created by xiangwenwen on 15/6/12. 6 | // Copyright (c) 2015年 xiangwenwen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | 12 | public struct STFile{ 13 | let fileName:String! 14 | let fileURL:String? 15 | let fileData:NSData? 16 | internal init(name:String,url:String?,data:NSData?){ 17 | self.fileName = name 18 | self.fileURL = url 19 | self.fileData = data 20 | } 21 | } 22 | 23 | public struct STFType{ 24 | let fileName:String! 25 | let fileType:String! 26 | internal init(name:String,type:String){ 27 | self.fileName = name 28 | self.fileType = type 29 | } 30 | } 31 | 32 | class STNetworkUpLoadFileManager: NSObject{ 33 | 34 | let HttpUrl:String 35 | let success:((data:NSData!,response:NSURLResponse!)-> Void)? 36 | let error:((error:NSError!)-> Void)? 37 | 38 | var STRequest:STNetworkRequest! 39 | var files:Array? 40 | 41 | init(url:String,files:Array?,success:((data:NSData!,response:NSURLResponse!)-> Void)? = nil,error:((error:NSError!)-> Void)? = nil,STRequest:STNetworkRequest?) { 42 | 43 | self.HttpUrl = url 44 | self.success = success 45 | self.error = error 46 | self.files = files 47 | if let _STRequest = STRequest{ 48 | self.STRequest = STRequest 49 | }else{ 50 | self.STRequest = STNetworkRequest(HttpURL: NSURL(string: HttpUrl)!) 51 | } 52 | } 53 | 54 | func fire()->Void{ 55 | let configur:NSURLSessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration() 56 | let session:NSURLSession = NSURLSession(configuration: configur) 57 | var _files:Array! 58 | if let STFileP = self.STRequest.STFileParams{ 59 | _files = self.STRequest.STFileParams! 60 | }else{ 61 | _files = self.files! 62 | } 63 | if _files[0].fileData == nil{ 64 | self.STRequest.HTTPMethod = HTTPMETHOD.POST.rawValue 65 | let task:NSURLSessionTask = session.dataTaskWithRequest(self.STRequest, completionHandler: { (data, response, error) -> Void in 66 | if error != nil{ 67 | let err = NSError(domain: "\(domain)", code: error.code, userInfo: error.userInfo) 68 | self.error?(error: err) 69 | }else{ 70 | if let HttpResponse = response as? NSHTTPURLResponse{ 71 | let code = HttpResponse.statusCode 72 | if code >= 400{ 73 | self.error?(error: NSError(domain: "\(domain)", code: code, userInfo: error.userInfo)) 74 | }else{ 75 | self.success?(data: data, response: response) 76 | } 77 | println("STNetWork HTTP Status: \(code) \(NSHTTPURLResponse.localizedStringForStatusCode(code))") 78 | } 79 | } 80 | }) 81 | task.resume() 82 | }else{ 83 | let task:NSURLSessionTask = session.uploadTaskWithRequest(self.STRequest, fromData: _files[0].fileData, completionHandler: { (data, response, error) -> Void in 84 | if error != nil{ 85 | let err = NSError(domain: "\(domain)", code: error.code, userInfo: error.userInfo) 86 | self.error?(error: err) 87 | }else{ 88 | self.success?(data: data, response: response) 89 | } 90 | }) 91 | task.resume() 92 | } 93 | } 94 | } -------------------------------------------------------------------------------- /STNetWorkDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Stan 4 | // 5 | // Created by xiangwenwen on 15/5/30. 6 | // Copyright (c) 2015年 xiangwenwen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /STNetWorkDemo/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /STNetWorkDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 28 | 37 | 46 | 55 | 64 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /STNetWorkDemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /STNetWorkDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | wen.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /STNetWorkDemo/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Stan 4 | // 5 | // Created by xiangwenwen on 15/5/30. 6 | // Copyright (c) 2015年 xiangwenwen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | 12 | class ViewController: UIViewController{ 13 | 14 | override func viewDidLoad() { 15 | super.viewDidLoad() 16 | } 17 | 18 | override func didReceiveMemoryWarning() { 19 | super.didReceiveMemoryWarning() 20 | // Dispose of any resources that can be recreated. 21 | } 22 | 23 | //普通的GET 请求 24 | 25 | @IBAction func sendGetHttp(sender: UIButton) { 26 | var url:String = "http://lcepy.github.io"; 27 | STNetwork.request(HTTPMETHOD.GET.rawValue, url: url, success: { (dataString, data, response) -> Void in 28 | println(dataString) 29 | }) { (error) -> Void in 30 | println(error) 31 | } 32 | 33 | } 34 | 35 | //带参数的GET 请求 36 | 37 | @IBAction func sendGetParamsHttp(sender: UIButton) { 38 | var url:String = "http://apis.baidu.com/apistore/aqiservice/aqi" 39 | var citys:Dictionary = Dictionary() 40 | citys["city"] = "北京" 41 | var header:Dictionary = Dictionary() 42 | header["apikey"] = "bce358f5243e78bad9ebd6da21f742d1" 43 | STNetwork.request(HTTPMETHOD.GET.rawValue, url: url, params: citys, header: header, success: { (dataString, data, response) -> Void in 44 | println(dataString) 45 | }) { (error) -> Void in 46 | println(error) 47 | } 48 | } 49 | 50 | //POST请求 带参数 51 | 52 | @IBAction func sendPostParamsHttp(sender: UIButton) { 53 | var url = "http://apis.baidu.com/apistore/idlocr/ocr" 54 | var httpArg = "fromdevice=pc&clientip=10.10.10.0&detecttype=LocateRecognize&languagetype=CHN_ENG&imagetype=1&image=/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABMNDxEPDBMREBEWFRMXHTAfHRsbHTsqLSMwRj5KSUU+RENNV29eTVJpU0NEYYRiaXN3fX59S12Jkoh5kW96fXj/2wBDARUWFh0ZHTkfHzl4UERQeHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHj/wAARCAAfACEDAREAAhEBAxEB/8QAGAABAQEBAQAAAAAAAAAAAAAAAAQDBQb/xAAjEAACAgICAgEFAAAAAAAAAAABAgADBBESIRMxBSIyQXGB/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/APawEBAQEBAgy8i8ZTVV3UY6V1eU2XoWDDZB19S646Gz39w9fkKsW1r8Wm2yo1PYis1be0JG9H9QNYCAgc35Cl3yuVuJZl0cB41rZQa32dt2y6OuOiOxo61vsLcVblxaVyXD3hFFjL6La7I/sDWAgICAgICB/9k=" 55 | var header:Dictionary = Dictionary() 56 | header["Content-Type"] = "application/x-www-form-urlencoded" 57 | header["apikey"] = "bce358f5243e78bad9ebd6da21f742d1" 58 | STNetwork.request(HTTPMETHOD.POST.rawValue, url: url, params: ["urlencoded":httpArg], header: header, success: { (dataString, data, response) -> Void in 59 | println(dataString) 60 | }) { (error) -> Void in 61 | println(error) 62 | } 63 | } 64 | 65 | //普通POST请求 66 | 67 | @IBAction func sendPOSTHttp(sender: UIButton) { 68 | var url = "http://apis.baidu.com/apistore/idlocr/ocr" 69 | var header:Dictionary = Dictionary() 70 | header["Content-Type"] = "application/x-www-form-urlencoded" 71 | header["apikey"] = "bce358f5243e78bad9ebd6da21f742d1" 72 | STNetwork.request(HTTPMETHOD.POST.rawValue, url: url, success: { (dataString, data, response) -> Void in 73 | println(dataString) 74 | }) { (error) -> Void in 75 | println(error) 76 | } 77 | 78 | } 79 | 80 | //上传文件 81 | 82 | @IBAction func sendUPLOADFILEHttp(sender: UIButton) { 83 | let url:String = "http://pitayaswift.sinaapp.com/pitaya.php" 84 | //模拟表单提交 85 | let fileType:STFType = STFType(name: "mage-gnome01-large", type: "jpg") 86 | STNetwork.upload(url, type: fileType, success: { (data, response) -> Void in 87 | println(NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments, error: nil)) 88 | }) { (error) -> Void in 89 | println(error) 90 | } 91 | } 92 | 93 | //下载文件 94 | 95 | @IBAction func sendDownloadFile(sender: UIButton) { 96 | var url:String = "http://content.battlenet.com.cn/wow/media/screenshots/screenshot-of-the-day/warlords-of-draenor/warlords-of-draenor-ss0420-large.jpg" 97 | STNetwork.download(url, success: { (url, response) -> Void in 98 | 99 | }) { (error) -> Void in 100 | 101 | } 102 | } 103 | } 104 | 105 | -------------------------------------------------------------------------------- /STNetWorkDemo/mage-gnome01-large.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightningminers/STNetWork/365119a84e07e188f9c5489ec56be7846888a818/STNetWorkDemo/mage-gnome01-large.jpg -------------------------------------------------------------------------------- /STNetWorkDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | wen.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /STNetWorkDemoTests/StanTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StanTests.swift 3 | // StanTests 4 | // 5 | // Created by xiangwenwen on 15/5/30. 6 | // Copyright (c) 2015年 xiangwenwen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import XCTest 11 | 12 | class StanTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | XCTAssert(true, "Pass") 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock() { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /STNetworking.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 172D49C71B19FBC9001DBADA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172D49C61B19FBC9001DBADA /* AppDelegate.swift */; }; 11 | 172D49C91B19FBC9001DBADA /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172D49C81B19FBC9001DBADA /* ViewController.swift */; }; 12 | 172D49CC1B19FBC9001DBADA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 172D49CA1B19FBC9001DBADA /* Main.storyboard */; }; 13 | 172D49CE1B19FBC9001DBADA /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 172D49CD1B19FBC9001DBADA /* Images.xcassets */; }; 14 | 172D49D11B19FBC9001DBADA /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 172D49CF1B19FBC9001DBADA /* LaunchScreen.xib */; }; 15 | 172D49DD1B19FBC9001DBADA /* StanTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172D49DC1B19FBC9001DBADA /* StanTests.swift */; }; 16 | 17A42E581B2A73E100B1545A /* STNetWorkResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A42E571B2A73E100B1545A /* STNetWorkResponse.swift */; }; 17 | 17A42E5A1B2AA5FE00B1545A /* STNetWorkRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A42E591B2AA5FE00B1545A /* STNetWorkRequest.swift */; }; 18 | 17A42E5E1B2AC1C400B1545A /* mage-gnome01-large.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 17A42E5D1B2AC1C400B1545A /* mage-gnome01-large.jpg */; }; 19 | 17A42E631B2AC86300B1545A /* STNetWorkDownloadManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A42E621B2AC86300B1545A /* STNetWorkDownloadManager.swift */; }; 20 | 17A42E651B2ACA3000B1545A /* STNetWorkUpLoadFileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A42E641B2ACA3000B1545A /* STNetWorkUpLoadFileManager.swift */; }; 21 | 17EE04241B1D4F9C00EAF47A /* STNetWorkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17EE04231B1D4F9C00EAF47A /* STNetWorkManager.swift */; }; 22 | 17EE04261B1D4FB500EAF47A /* STNetWork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17EE04251B1D4FB500EAF47A /* STNetWork.swift */; }; 23 | /* End PBXBuildFile section */ 24 | 25 | /* Begin PBXContainerItemProxy section */ 26 | 172D49D71B19FBC9001DBADA /* PBXContainerItemProxy */ = { 27 | isa = PBXContainerItemProxy; 28 | containerPortal = 172D49B91B19FBC8001DBADA /* Project object */; 29 | proxyType = 1; 30 | remoteGlobalIDString = 172D49C01B19FBC8001DBADA; 31 | remoteInfo = Stan; 32 | }; 33 | /* End PBXContainerItemProxy section */ 34 | 35 | /* Begin PBXFileReference section */ 36 | 172D49C11B19FBC9001DBADA /* STNetworking.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = STNetworking.app; sourceTree = BUILT_PRODUCTS_DIR; }; 37 | 172D49C51B19FBC9001DBADA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 38 | 172D49C61B19FBC9001DBADA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 39 | 172D49C81B19FBC9001DBADA /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 40 | 172D49CB1B19FBC9001DBADA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 41 | 172D49CD1B19FBC9001DBADA /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 42 | 172D49D01B19FBC9001DBADA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 43 | 172D49D61B19FBC9001DBADA /* STNetworkingTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = STNetworkingTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 44 | 172D49DB1B19FBC9001DBADA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 45 | 172D49DC1B19FBC9001DBADA /* StanTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StanTests.swift; sourceTree = ""; }; 46 | 17A42E571B2A73E100B1545A /* STNetWorkResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = STNetWorkResponse.swift; sourceTree = ""; }; 47 | 17A42E591B2AA5FE00B1545A /* STNetWorkRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = STNetWorkRequest.swift; sourceTree = ""; }; 48 | 17A42E5D1B2AC1C400B1545A /* mage-gnome01-large.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "mage-gnome01-large.jpg"; sourceTree = ""; }; 49 | 17A42E621B2AC86300B1545A /* STNetWorkDownloadManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = STNetWorkDownloadManager.swift; sourceTree = ""; }; 50 | 17A42E641B2ACA3000B1545A /* STNetWorkUpLoadFileManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = STNetWorkUpLoadFileManager.swift; sourceTree = ""; }; 51 | 17EE04231B1D4F9C00EAF47A /* STNetWorkManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = STNetWorkManager.swift; sourceTree = ""; }; 52 | 17EE04251B1D4FB500EAF47A /* STNetWork.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = STNetWork.swift; sourceTree = ""; }; 53 | /* End PBXFileReference section */ 54 | 55 | /* Begin PBXFrameworksBuildPhase section */ 56 | 172D49BE1B19FBC8001DBADA /* Frameworks */ = { 57 | isa = PBXFrameworksBuildPhase; 58 | buildActionMask = 2147483647; 59 | files = ( 60 | ); 61 | runOnlyForDeploymentPostprocessing = 0; 62 | }; 63 | 172D49D31B19FBC9001DBADA /* Frameworks */ = { 64 | isa = PBXFrameworksBuildPhase; 65 | buildActionMask = 2147483647; 66 | files = ( 67 | ); 68 | runOnlyForDeploymentPostprocessing = 0; 69 | }; 70 | /* End PBXFrameworksBuildPhase section */ 71 | 72 | /* Begin PBXGroup section */ 73 | 1726B3FE1B1B5E1500A8CF17 /* STNetwork */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | 17EE04231B1D4F9C00EAF47A /* STNetWorkManager.swift */, 77 | 17EE04251B1D4FB500EAF47A /* STNetWork.swift */, 78 | 17A42E571B2A73E100B1545A /* STNetWorkResponse.swift */, 79 | 17A42E591B2AA5FE00B1545A /* STNetWorkRequest.swift */, 80 | 17A42E621B2AC86300B1545A /* STNetWorkDownloadManager.swift */, 81 | 17A42E641B2ACA3000B1545A /* STNetWorkUpLoadFileManager.swift */, 82 | ); 83 | path = STNetwork; 84 | sourceTree = ""; 85 | }; 86 | 172D49B81B19FBC8001DBADA = { 87 | isa = PBXGroup; 88 | children = ( 89 | 1726B3FE1B1B5E1500A8CF17 /* STNetwork */, 90 | 172D49C31B19FBC9001DBADA /* STNetworkDemo */, 91 | 172D49D91B19FBC9001DBADA /* STNetworkDemoTests */, 92 | 172D49C21B19FBC9001DBADA /* Products */, 93 | ); 94 | sourceTree = ""; 95 | }; 96 | 172D49C21B19FBC9001DBADA /* Products */ = { 97 | isa = PBXGroup; 98 | children = ( 99 | 172D49C11B19FBC9001DBADA /* STNetworking.app */, 100 | 172D49D61B19FBC9001DBADA /* STNetworkingTests.xctest */, 101 | ); 102 | name = Products; 103 | sourceTree = ""; 104 | }; 105 | 172D49C31B19FBC9001DBADA /* STNetworkDemo */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | 172D49C61B19FBC9001DBADA /* AppDelegate.swift */, 109 | 172D49C81B19FBC9001DBADA /* ViewController.swift */, 110 | 172D49CA1B19FBC9001DBADA /* Main.storyboard */, 111 | 172D49CD1B19FBC9001DBADA /* Images.xcassets */, 112 | 172D49CF1B19FBC9001DBADA /* LaunchScreen.xib */, 113 | 17A42E5D1B2AC1C400B1545A /* mage-gnome01-large.jpg */, 114 | 172D49C41B19FBC9001DBADA /* Supporting Files */, 115 | ); 116 | name = STNetworkDemo; 117 | path = STNetWorkDemo; 118 | sourceTree = ""; 119 | }; 120 | 172D49C41B19FBC9001DBADA /* Supporting Files */ = { 121 | isa = PBXGroup; 122 | children = ( 123 | 172D49C51B19FBC9001DBADA /* Info.plist */, 124 | ); 125 | name = "Supporting Files"; 126 | sourceTree = ""; 127 | }; 128 | 172D49D91B19FBC9001DBADA /* STNetworkDemoTests */ = { 129 | isa = PBXGroup; 130 | children = ( 131 | 172D49DC1B19FBC9001DBADA /* StanTests.swift */, 132 | 172D49DA1B19FBC9001DBADA /* Supporting Files */, 133 | ); 134 | name = STNetworkDemoTests; 135 | path = STNetWorkDemoTests; 136 | sourceTree = ""; 137 | }; 138 | 172D49DA1B19FBC9001DBADA /* Supporting Files */ = { 139 | isa = PBXGroup; 140 | children = ( 141 | 172D49DB1B19FBC9001DBADA /* Info.plist */, 142 | ); 143 | name = "Supporting Files"; 144 | sourceTree = ""; 145 | }; 146 | /* End PBXGroup section */ 147 | 148 | /* Begin PBXNativeTarget section */ 149 | 172D49C01B19FBC8001DBADA /* STNetworking */ = { 150 | isa = PBXNativeTarget; 151 | buildConfigurationList = 172D49E01B19FBC9001DBADA /* Build configuration list for PBXNativeTarget "STNetworking" */; 152 | buildPhases = ( 153 | 172D49BD1B19FBC8001DBADA /* Sources */, 154 | 172D49BE1B19FBC8001DBADA /* Frameworks */, 155 | 172D49BF1B19FBC8001DBADA /* Resources */, 156 | ); 157 | buildRules = ( 158 | ); 159 | dependencies = ( 160 | ); 161 | name = STNetworking; 162 | productName = Stan; 163 | productReference = 172D49C11B19FBC9001DBADA /* STNetworking.app */; 164 | productType = "com.apple.product-type.application"; 165 | }; 166 | 172D49D51B19FBC9001DBADA /* STNetworkingTests */ = { 167 | isa = PBXNativeTarget; 168 | buildConfigurationList = 172D49E31B19FBC9001DBADA /* Build configuration list for PBXNativeTarget "STNetworkingTests" */; 169 | buildPhases = ( 170 | 172D49D21B19FBC9001DBADA /* Sources */, 171 | 172D49D31B19FBC9001DBADA /* Frameworks */, 172 | 172D49D41B19FBC9001DBADA /* Resources */, 173 | ); 174 | buildRules = ( 175 | ); 176 | dependencies = ( 177 | 172D49D81B19FBC9001DBADA /* PBXTargetDependency */, 178 | ); 179 | name = STNetworkingTests; 180 | productName = StanTests; 181 | productReference = 172D49D61B19FBC9001DBADA /* STNetworkingTests.xctest */; 182 | productType = "com.apple.product-type.bundle.unit-test"; 183 | }; 184 | /* End PBXNativeTarget section */ 185 | 186 | /* Begin PBXProject section */ 187 | 172D49B91B19FBC8001DBADA /* Project object */ = { 188 | isa = PBXProject; 189 | attributes = { 190 | LastUpgradeCheck = 0630; 191 | ORGANIZATIONNAME = xiangwenwen; 192 | TargetAttributes = { 193 | 172D49C01B19FBC8001DBADA = { 194 | CreatedOnToolsVersion = 6.3.2; 195 | }; 196 | 172D49D51B19FBC9001DBADA = { 197 | CreatedOnToolsVersion = 6.3.2; 198 | TestTargetID = 172D49C01B19FBC8001DBADA; 199 | }; 200 | }; 201 | }; 202 | buildConfigurationList = 172D49BC1B19FBC8001DBADA /* Build configuration list for PBXProject "STNetworking" */; 203 | compatibilityVersion = "Xcode 3.2"; 204 | developmentRegion = English; 205 | hasScannedForEncodings = 0; 206 | knownRegions = ( 207 | en, 208 | Base, 209 | ); 210 | mainGroup = 172D49B81B19FBC8001DBADA; 211 | productRefGroup = 172D49C21B19FBC9001DBADA /* Products */; 212 | projectDirPath = ""; 213 | projectRoot = ""; 214 | targets = ( 215 | 172D49C01B19FBC8001DBADA /* STNetworking */, 216 | 172D49D51B19FBC9001DBADA /* STNetworkingTests */, 217 | ); 218 | }; 219 | /* End PBXProject section */ 220 | 221 | /* Begin PBXResourcesBuildPhase section */ 222 | 172D49BF1B19FBC8001DBADA /* Resources */ = { 223 | isa = PBXResourcesBuildPhase; 224 | buildActionMask = 2147483647; 225 | files = ( 226 | 172D49CC1B19FBC9001DBADA /* Main.storyboard in Resources */, 227 | 172D49D11B19FBC9001DBADA /* LaunchScreen.xib in Resources */, 228 | 172D49CE1B19FBC9001DBADA /* Images.xcassets in Resources */, 229 | 17A42E5E1B2AC1C400B1545A /* mage-gnome01-large.jpg in Resources */, 230 | ); 231 | runOnlyForDeploymentPostprocessing = 0; 232 | }; 233 | 172D49D41B19FBC9001DBADA /* Resources */ = { 234 | isa = PBXResourcesBuildPhase; 235 | buildActionMask = 2147483647; 236 | files = ( 237 | ); 238 | runOnlyForDeploymentPostprocessing = 0; 239 | }; 240 | /* End PBXResourcesBuildPhase section */ 241 | 242 | /* Begin PBXSourcesBuildPhase section */ 243 | 172D49BD1B19FBC8001DBADA /* Sources */ = { 244 | isa = PBXSourcesBuildPhase; 245 | buildActionMask = 2147483647; 246 | files = ( 247 | 17A42E651B2ACA3000B1545A /* STNetWorkUpLoadFileManager.swift in Sources */, 248 | 172D49C91B19FBC9001DBADA /* ViewController.swift in Sources */, 249 | 17A42E5A1B2AA5FE00B1545A /* STNetWorkRequest.swift in Sources */, 250 | 172D49C71B19FBC9001DBADA /* AppDelegate.swift in Sources */, 251 | 17A42E581B2A73E100B1545A /* STNetWorkResponse.swift in Sources */, 252 | 17EE04241B1D4F9C00EAF47A /* STNetWorkManager.swift in Sources */, 253 | 17A42E631B2AC86300B1545A /* STNetWorkDownloadManager.swift in Sources */, 254 | 17EE04261B1D4FB500EAF47A /* STNetWork.swift in Sources */, 255 | ); 256 | runOnlyForDeploymentPostprocessing = 0; 257 | }; 258 | 172D49D21B19FBC9001DBADA /* Sources */ = { 259 | isa = PBXSourcesBuildPhase; 260 | buildActionMask = 2147483647; 261 | files = ( 262 | 172D49DD1B19FBC9001DBADA /* StanTests.swift in Sources */, 263 | ); 264 | runOnlyForDeploymentPostprocessing = 0; 265 | }; 266 | /* End PBXSourcesBuildPhase section */ 267 | 268 | /* Begin PBXTargetDependency section */ 269 | 172D49D81B19FBC9001DBADA /* PBXTargetDependency */ = { 270 | isa = PBXTargetDependency; 271 | target = 172D49C01B19FBC8001DBADA /* STNetworking */; 272 | targetProxy = 172D49D71B19FBC9001DBADA /* PBXContainerItemProxy */; 273 | }; 274 | /* End PBXTargetDependency section */ 275 | 276 | /* Begin PBXVariantGroup section */ 277 | 172D49CA1B19FBC9001DBADA /* Main.storyboard */ = { 278 | isa = PBXVariantGroup; 279 | children = ( 280 | 172D49CB1B19FBC9001DBADA /* Base */, 281 | ); 282 | name = Main.storyboard; 283 | sourceTree = ""; 284 | }; 285 | 172D49CF1B19FBC9001DBADA /* LaunchScreen.xib */ = { 286 | isa = PBXVariantGroup; 287 | children = ( 288 | 172D49D01B19FBC9001DBADA /* Base */, 289 | ); 290 | name = LaunchScreen.xib; 291 | sourceTree = ""; 292 | }; 293 | /* End PBXVariantGroup section */ 294 | 295 | /* Begin XCBuildConfiguration section */ 296 | 172D49DE1B19FBC9001DBADA /* Debug */ = { 297 | isa = XCBuildConfiguration; 298 | buildSettings = { 299 | ALWAYS_SEARCH_USER_PATHS = NO; 300 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 301 | CLANG_CXX_LIBRARY = "libc++"; 302 | CLANG_ENABLE_MODULES = YES; 303 | CLANG_ENABLE_OBJC_ARC = YES; 304 | CLANG_WARN_BOOL_CONVERSION = YES; 305 | CLANG_WARN_CONSTANT_CONVERSION = YES; 306 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 307 | CLANG_WARN_EMPTY_BODY = YES; 308 | CLANG_WARN_ENUM_CONVERSION = YES; 309 | CLANG_WARN_INT_CONVERSION = YES; 310 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 311 | CLANG_WARN_UNREACHABLE_CODE = YES; 312 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 313 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 314 | COPY_PHASE_STRIP = NO; 315 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 316 | ENABLE_STRICT_OBJC_MSGSEND = YES; 317 | GCC_C_LANGUAGE_STANDARD = gnu99; 318 | GCC_DYNAMIC_NO_PIC = NO; 319 | GCC_NO_COMMON_BLOCKS = YES; 320 | GCC_OPTIMIZATION_LEVEL = 0; 321 | GCC_PREPROCESSOR_DEFINITIONS = ( 322 | "DEBUG=1", 323 | "$(inherited)", 324 | ); 325 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 326 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 327 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 328 | GCC_WARN_UNDECLARED_SELECTOR = YES; 329 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 330 | GCC_WARN_UNUSED_FUNCTION = YES; 331 | GCC_WARN_UNUSED_VARIABLE = YES; 332 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 333 | MTL_ENABLE_DEBUG_INFO = YES; 334 | ONLY_ACTIVE_ARCH = YES; 335 | SDKROOT = iphoneos; 336 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 337 | }; 338 | name = Debug; 339 | }; 340 | 172D49DF1B19FBC9001DBADA /* Release */ = { 341 | isa = XCBuildConfiguration; 342 | buildSettings = { 343 | ALWAYS_SEARCH_USER_PATHS = NO; 344 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 345 | CLANG_CXX_LIBRARY = "libc++"; 346 | CLANG_ENABLE_MODULES = YES; 347 | CLANG_ENABLE_OBJC_ARC = YES; 348 | CLANG_WARN_BOOL_CONVERSION = YES; 349 | CLANG_WARN_CONSTANT_CONVERSION = YES; 350 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 351 | CLANG_WARN_EMPTY_BODY = YES; 352 | CLANG_WARN_ENUM_CONVERSION = YES; 353 | CLANG_WARN_INT_CONVERSION = YES; 354 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 355 | CLANG_WARN_UNREACHABLE_CODE = YES; 356 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 357 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 358 | COPY_PHASE_STRIP = NO; 359 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 360 | ENABLE_NS_ASSERTIONS = NO; 361 | ENABLE_STRICT_OBJC_MSGSEND = YES; 362 | GCC_C_LANGUAGE_STANDARD = gnu99; 363 | GCC_NO_COMMON_BLOCKS = YES; 364 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 365 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 366 | GCC_WARN_UNDECLARED_SELECTOR = YES; 367 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 368 | GCC_WARN_UNUSED_FUNCTION = YES; 369 | GCC_WARN_UNUSED_VARIABLE = YES; 370 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 371 | MTL_ENABLE_DEBUG_INFO = NO; 372 | SDKROOT = iphoneos; 373 | VALIDATE_PRODUCT = YES; 374 | }; 375 | name = Release; 376 | }; 377 | 172D49E11B19FBC9001DBADA /* Debug */ = { 378 | isa = XCBuildConfiguration; 379 | buildSettings = { 380 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 381 | CLANG_ENABLE_MODULES = YES; 382 | INFOPLIST_FILE = STNetWorkDemo/Info.plist; 383 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 384 | PRODUCT_NAME = STNetworking; 385 | SWIFT_OBJC_BRIDGING_HEADER = ""; 386 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 387 | }; 388 | name = Debug; 389 | }; 390 | 172D49E21B19FBC9001DBADA /* Release */ = { 391 | isa = XCBuildConfiguration; 392 | buildSettings = { 393 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 394 | CLANG_ENABLE_MODULES = YES; 395 | INFOPLIST_FILE = STNetWorkDemo/Info.plist; 396 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 397 | PRODUCT_NAME = STNetworking; 398 | SWIFT_OBJC_BRIDGING_HEADER = ""; 399 | }; 400 | name = Release; 401 | }; 402 | 172D49E41B19FBC9001DBADA /* Debug */ = { 403 | isa = XCBuildConfiguration; 404 | buildSettings = { 405 | BUNDLE_LOADER = "$(TEST_HOST)"; 406 | FRAMEWORK_SEARCH_PATHS = ( 407 | "$(SDKROOT)/Developer/Library/Frameworks", 408 | "$(inherited)", 409 | ); 410 | GCC_PREPROCESSOR_DEFINITIONS = ( 411 | "DEBUG=1", 412 | "$(inherited)", 413 | ); 414 | INFOPLIST_FILE = STNetWorkDemoTests/Info.plist; 415 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 416 | PRODUCT_NAME = STNetworkingTests; 417 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/STNetWork.app/Stan"; 418 | }; 419 | name = Debug; 420 | }; 421 | 172D49E51B19FBC9001DBADA /* Release */ = { 422 | isa = XCBuildConfiguration; 423 | buildSettings = { 424 | BUNDLE_LOADER = "$(TEST_HOST)"; 425 | FRAMEWORK_SEARCH_PATHS = ( 426 | "$(SDKROOT)/Developer/Library/Frameworks", 427 | "$(inherited)", 428 | ); 429 | INFOPLIST_FILE = STNetWorkDemoTests/Info.plist; 430 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 431 | PRODUCT_NAME = STNetworkingTests; 432 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/STNetWork.app/Stan"; 433 | }; 434 | name = Release; 435 | }; 436 | /* End XCBuildConfiguration section */ 437 | 438 | /* Begin XCConfigurationList section */ 439 | 172D49BC1B19FBC8001DBADA /* Build configuration list for PBXProject "STNetworking" */ = { 440 | isa = XCConfigurationList; 441 | buildConfigurations = ( 442 | 172D49DE1B19FBC9001DBADA /* Debug */, 443 | 172D49DF1B19FBC9001DBADA /* Release */, 444 | ); 445 | defaultConfigurationIsVisible = 0; 446 | defaultConfigurationName = Release; 447 | }; 448 | 172D49E01B19FBC9001DBADA /* Build configuration list for PBXNativeTarget "STNetworking" */ = { 449 | isa = XCConfigurationList; 450 | buildConfigurations = ( 451 | 172D49E11B19FBC9001DBADA /* Debug */, 452 | 172D49E21B19FBC9001DBADA /* Release */, 453 | ); 454 | defaultConfigurationIsVisible = 0; 455 | defaultConfigurationName = Release; 456 | }; 457 | 172D49E31B19FBC9001DBADA /* Build configuration list for PBXNativeTarget "STNetworkingTests" */ = { 458 | isa = XCConfigurationList; 459 | buildConfigurations = ( 460 | 172D49E41B19FBC9001DBADA /* Debug */, 461 | 172D49E51B19FBC9001DBADA /* Release */, 462 | ); 463 | defaultConfigurationIsVisible = 0; 464 | defaultConfigurationName = Release; 465 | }; 466 | /* End XCConfigurationList section */ 467 | }; 468 | rootObject = 172D49B91B19FBC8001DBADA /* Project object */; 469 | } 470 | -------------------------------------------------------------------------------- /STNetworking.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /pheasant-729491_640.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightningminers/STNetWork/365119a84e07e188f9c5489ec56be7846888a818/pheasant-729491_640.jpg --------------------------------------------------------------------------------