Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tkc
Last active August 13, 2016 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkc/b38e9d81b1ca54c31bea86423cd6fc4d to your computer and use it in GitHub Desktop.
Save tkc/b38e9d81b1ca54c31bea86423cd6fc4d to your computer and use it in GitHub Desktop.
import Alamofire
import SwiftyJSON
public class ApiConnection{
func getArticle(id:Int,callback: (String) -> Void) -> Void {
let url = "http://0.0.0.0:8080/article/" + String(id)
Alamofire.request(.GET, url)
.responseJSON {
response in
guard let object = response.result.value else {
return
}
let json = JSON(object)
let name = json["Name"].string!
callback(name)
}
}
}
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
import XCTest
@testable import app
let connection=app.ApiConnection()
class apiTests: XCTestCase {
override func setUp() {
super.setUp()
}
override func tearDown() {
super.tearDown()
}
func testApi() {
let connection=app.ApiConnection()
let articleId = 1;
let expectation = expectationWithDescription("scync")
connection.getArticle(articleId){Name in
print(Name)
expectation.fulfill()
}
waitForExpectationsWithTimeout(1.0, handler: nil)
}
func testPerformanceExample() {
self.measureBlock {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment