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 IdentifiableDispatchQueue { | |
let key = DispatchSpecificKey<UUID>() | |
let id = UUID() | |
let queue: DispatchQueue | |
convenience init(label: String) { | |
let queue = DispatchQueue(label: label) | |
self.init(queue: queue) |
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
public enum Result<T, E: Error> { | |
case success(T) | |
case failure(E) | |
} | |
public enum NetworkError: Error { | |
case invalidJson | |
case badRequest | |
case timeout | |
} |
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 BaseJsonDeserializer<T>: JsonDeserializer { | |
init() { | |
guard type(of: self) != BaseJsonDeserializer.self | |
else { fatalError("do not initialize this abstract class directly") } | |
} | |
func parse(json: [String : Any]) -> T { | |
fatalError("Abstract class. Subclass must override") | |
} | |
} |
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 SomeDeserializer<T, D: JsonDeserializer>: JsonDeserializer { | |
private let deserializer: D | |
init<D: JsonDeserializer>(deserializer: D) where D.Response == T { | |
self.deserializer = deserializer | |
} | |
func parse(json: [String : Any]) -> T { | |
return deserializer.parse(json: json) | |
} |
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 SomeDeserializer<T>: JsonDeserializer { | |
private let deserializer: JsonDeserializer | |
init<D: JsonDeserializer>(deserializer: D) where D.Response == T { | |
self.deserializer = deserializer | |
} | |
func parse(json: [String : Any]) -> T { | |
return deserializer.parse(json: json) | |
} |
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 DeserializerBox<D: JsonDeserializer> { | |
let deserializer: D | |
init(deserializer: D) { | |
self.deserializer = deserializer | |
} | |
} | |
class Session<P>: NetworkSession { | |
typealias Payload = P |
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 Result<T, E: Error> { | |
case success(T) | |
case failure(E) | |
} | |
enum NetworkError: Error { | |
case invalidJson | |
case badRequest | |
case timeout | |
} |
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
/* | |
from console. `po NSHomeDirectory()` | |
from terminal cd to that path | |
cd into Documents | |
LogFile.txt should be there | |
To see content update live run tail -F LogFile.txt | |
*/ | |
public class BasicLogger: NSObject { |
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 BasicLogger: NSObject { | |
private static let queue = dispatch_queue_create("com.vhart.BasicLoggerQueue", DISPATCH_QUEUE_SERIAL) | |
private static let dateFormatter = NSDateFormatter() | |
static var filePath: String { | |
return fileUrl.path! | |
} | |
static var fileUrl: NSURL { |
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 UIKit | |
import Foundation | |
struct StringLayoutHandler { | |
enum SerializationTokens: String { | |
case tab = "T" | |
case newline = "N" | |
var token: String { return "#" + rawValue } |