Skip to content

Instantly share code, notes, and snippets.

View diatrevolo's full-sized avatar
🔈

Roberto J. Osorio-Goenaga diatrevolo

🔈
View GitHub Profile
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)
{
"count": 3,
"items": ["car", "boat", "airplane"]
}
{
"count": 3,
"concepts": ["art", "beauty", "ennui"]
}
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.
import Foundation
import Alamofire
struct MyRESTClient {
let url: NSURL
let manager: Manager
init(url: NSURL, manager: Manager?) {
self.url = url
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
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")
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
@diatrevolo
diatrevolo / DeviceUID.m
Last active March 10, 2016 20:20 — forked from miguelcma/DeviceUID.m
iOS Unique Device ID that persists between app reinstalls
/* DeviceUID.h
#import <Foundation/Foundation.h>
@interface DeviceUID : NSObject
+ (NSString *)uid;
@end
*/
// Device.m