-
- Add a third-party library ASIHTTPRequest
-
- Add systemconfiguration.framework, Mobilecoreservices.framework,coregraphics.framework, and Libz.1.2.3.dylib class libraries
-
- Add-fno-objc-arc identity to the compiler flags for. m files in Build phases-Compile Source
-
- inserting in the bridge files of Swift and Objective-c #import "ASIHTTPRequest.h"
-
- Write code that accesses the background
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 uses ASIHTTPRequest