Skip to content

Instantly share code, notes, and snippets.

@a821246710
a821246710 / DebugFPS.swift
Created October 21, 2020 07:17
iOS FPS Bugger
/**
Provide a convenience way to examine FPS, to get more precise and detail info you still need to use Instruments.
*/
@objc
class DebugFPS: NSObject {
private static let shared = DebugFPS() // static is lazy
private var lastScreenUpdateAt: TimeInterval? // mach_absolute_time
private var accumulatedFrames = 0
@a821246710
a821246710 / APIRequest.swift
Last active March 9, 2020 03:00
Testable Network Pattern
protocol APIRequest {
associatedtype RequestDataType
associatedtype ResponseDataType
func makeRequest(from data: RequestDataType) throws -> URLRequest
func parseResponse(data: Data) throws -> ResponseDataType
}
class APIRequestLoader<T: APIRequest> {
let apiRequest: T
class ApiTimeHelper {
static private var dic = [String: NSDate]()
static private var dicStopTimes = [String: Int]()
static func start(tag: String) {
dic.updateValue(NSDate(), forKey: tag)
dicStopTimes.updateValue(0, forKey: tag)
}
static func stop(tag: String, note: String? = nil) {