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
/* | |
For this Gist, we have two sides: sender and receiver. The same user can be a sender and a receiver, but I will separate this | |
two roles to be more clear. | |
This gist assumes thatyou already have a MCSession created, and the peers are connected, | |
*/ | |
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
// | |
// ClientConfig.swift | |
// EventCast | |
// | |
// Created by Lucas Eduardo on 27/10/15. | |
// Copyright © 2015 RNCDev. All rights reserved. | |
// | |
import Foundation | |
import Alamofire |
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
// | |
// Event.swift | |
// EventCast | |
// | |
// Created by Lucas Eduardo on 27/10/15. | |
// Copyright © 2015 RNCDev. All rights reserved. | |
// | |
import Foundation | |
import CoreData |
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
// | |
// EventClient.swift | |
// EventCast | |
// | |
// Created by Lucas Eduardo on 27/10/15. | |
// Copyright © 2015 RNCDev. All rights reserved. | |
// | |
import Alamofire |
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
// | |
// NSManagedObject+ActiveRecord.swift | |
// EventCast | |
// | |
// Created by Lucas Eduardo on 04/11/15. | |
// Copyright © 2015 RNCDev. All rights reserved. | |
// | |
import Foundation | |
import CoreData |
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
protocol Dispatcher { | |
func execute(request: URLRequest, success: (Data) -> Void, failure: (Error) -> Void) | |
} |
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
protocol Dispatcher { | |
associatedtype Output | |
associatedtype Request | |
func execute(request: Request, success: (Output) -> Void, failure: (Error) -> Void) | |
} |
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
struct HTTPDispatcher: Dispatcher { | |
func execute(request: URLRequest, success: (Data) -> Void, failure: (Error) -> Void) { | |
// executes HTTP requests using URLSession | |
// … | |
} | |
} | |
struct TestHTTPDispatcher: Dispatcher { | |
func execute(request: URLRequest, success: (Data) -> Void, failure: (Error) -> Void) { | |
// to be used for unit tests, returns mocked data |
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
let task1 = GetMoviesTask(dispatcher: HTTPDispatcher()) | |
let task2 = GetMoviesTask(dispatcher: TestHTTPDispatcher()) |
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
struct GetMoviesTask { | |
let dispatcher: Dispatcher | |
func load(success: ([Movie]) -> Void, failure: (Error) -> Void) { | |
let request = URLRequest(url: URL(string: “www.mydomain.com/movies")!) | |
dispatcher.execute(request: request, success: { data in | |
// (…) | |
}, failure: { error in | |
// (…) | |
}) |
OlderNewer