Last active
August 13, 2016 18:39
-
-
Save tkc/b38e9d81b1ca54c31bea86423cd6fc4d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<key>NSAppTransportSecurity</key> | |
<dict> | |
<key>NSAllowsArbitraryLoads</key> | |
<true/> | |
</dict> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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