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
enum RemoteError: Error { | |
case networkError(Error) | |
case parseError(Error) | |
case emptyResponse | |
} | |
struct RemoteResponse: Codable { | |
let enitities: [Entity] | |
let numberOfEntities: Int | |
} |
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
var subscriptions = Set<AnyCancellable>() | |
guard let url = URL(string: "https://jsonplaceholder.typicode.com/todos/1") else { return } | |
// With Error handling | |
URLSession.shared | |
.dataTaskPublisher(for: url) | |
.tryMap { data, response in | |
try JSONDecoder().decode(SampleData.self, from: data) | |
} |
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 Foundation | |
struct QuizQuestionItem: Equatable { | |
var allAnswers: [QuizAnswerItem] | |
var rightAnswer: QuizAnswerItem | |
} | |
struct QuizAnswerItem: Equatable { | |
} |
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
extension String { | |
static func random(length: Int = 10) -> String { | |
let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | |
return String((0..<length).map{ _ in letters.randomElement()! }) | |
} | |
} |
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
extension URLRequest { | |
public func curl(pretty:Bool = false) -> String { | |
var data : String = "" | |
let complement = pretty ? "\\\n" : "" | |
let method = "-X \(self.httpMethod ?? "GET") \(complement)" | |
let url = "\"" + (self.url?.absoluteString ?? "") + "\"" | |
var header = "" |
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
#if DEBUG | |
if let jsonResult = try JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary { | |
print(jsonResult) | |
} | |
// OR | |
print(String(data: data, encoding:.utf8) ?? “Not UTF8”) | |
#endif |
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
class StandingsEndpointLocalRequest: StandingsEndpointRequest { | |
let tournamentId: Int32 | |
let file: String | |
init(file: String, tournamentId: Int32) { | |
self.file = file | |
self.tournamentId = tournamentId | |
} |
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
[ | |
{ | |
"tournamentId": 10, | |
"title": "A Standing", | |
"content": "A Content", | |
"groupName": "Group A" | |
}, | |
{ | |
"tournamentId": 10, | |
"title": "A Standing", |
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
class StandingsDatasource: ManagedDataSource { | |
private let endpointRequest: StandingsEndpointRequest | |
private let entityRequest: StandingsEntityRequest | |
private let dataController: RequestDataConnectionController | |
init(endpointRequest: StandingsEndpointRequest, | |
entityRequest: StandingsEntityRequest, | |
managedObjectContext: NSManagedObjectContext, | |
dataController: RequestDataConnectionController) { |
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
struct StandingsEntityRequest: EntityRequest { | |
let entityName: String | |
let predicate: NSPredicate? | |
init(tournamentId: Int32, | |
groupName: String? = nil) { | |
self.entityName = "Standing" | |
let predicates = [ |