This file contains 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 Foundation | |
import Alamofire | |
struct MyRESTClient { | |
let url: NSURL // this, being in a struct, will become a parameter of the initializer automatically | |
func getAvailableItems(completion: ((items: [MyItem]?) -> ())) { | |
Alamofire.request(.GET, url.absoluteString + "/items", parameters: nil) | |
.validate(statusCode: 200..<300) |
This file contains 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
{ | |
"count": 3, | |
"items": ["car", "boat", "airplane"] | |
} |
This file contains 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
{ | |
"count": 3, | |
"concepts": ["art", "beauty", "ennui"] | |
} |
This file contains 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
“GARBAGE” |
This file contains 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 | |
import Alamofire | |
class MyRESTClientTests: XCTestCase { | |
var client: MyRESTClient? | |
var manager: Alamofire.Manager? | |
override func setUp() { | |
super.setUp() | |
// Put setup code here. This method is called before the invocation of each test method in the class. |
This file contains 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 Foundation | |
import Alamofire | |
struct MyRESTClient { | |
let url: NSURL | |
let manager: Manager | |
init(url: NSURL, manager: Manager?) { | |
self.url = url |
This file contains 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
func testGetItems_withArray() { | |
client = MyRESTClient(url: NSURL(string: "http://notNil")!, manager: manager!) | |
let expectation = expectationWithDescription("GetJSONArray") | |
var itemsArray: [MyItem]? | |
client?.getAvailableItems { (items) -> () in | |
itemsArray = items | |
expectation.fulfill() | |
} | |
waitForExpectationsWithTimeout(5) { (error: NSError?) -> Void in |
This file contains 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
func testGetItems_withNil() { | |
client = MyRESTClient(url: NSURL(string: "http://nil")!, manager: manager!) | |
let expectation = expectationWithDescription("GetJSONArray") | |
var itemsArray: [MyItem]? | |
client?.getAvailableItems { (items) -> () in | |
itemsArray = items | |
expectation.fulfill() | |
} | |
waitForExpectationsWithTimeout(5) { (error: NSError?) -> Void in | |
XCTAssert(itemsArray == nil, "Array should be nil when no items are found") |
This file contains 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
func testGetItems_withIncorrectArray() { | |
client = MyRESTClient(url: NSURL(string: "http://notRight")!, manager: manager!) | |
let expectation = expectationWithDescription("GetJSONArray") | |
var itemsArray: [MyItem]? | |
client?.getAvailableItems { (items) -> () in | |
itemsArray = items | |
expectation.fulfill() | |
} | |
waitForExpectationsWithTimeout(5) { (error: NSError?) -> Void in |
This file contains 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
/* DeviceUID.h | |
#import <Foundation/Foundation.h> | |
@interface DeviceUID : NSObject | |
+ (NSString *)uid; | |
@end | |
*/ | |
// Device.m |
OlderNewer