Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Karthik samy karthikAdaptavant

🎯
Focusing
View GitHub Profile
View InstrumentsViewController.swift
class InstrumentsViewController: UIViewController {
@IBOutlet weak var instrumentsTableView: UITableView! {
didSet {
instrumentsTableView.delegate = self
instrumentsTableView.dataSource = self
instrumentsTableView.tableFooterView = .init()
let cellNib = UINib(nibName: "InstrumentCell", bundle: .main)
instrumentsTableView.register(cellNib, forCellReuseIdentifier: "InstrumentCell")
}
View InstrumentCell.swift
class InstrumentCell: UITableViewCell {
@IBOutlet weak var title: UILabel!
@IBOutlet weak var subtitle: UILabel!
var instrument: Instrument!
override func awakeFromNib() {
super.awakeFromNib()
}
View Cache.swift
import UIKit
// According to article by John Sundell
// https://www.swiftbysundell.com/articles/caching-in-swift/
final class Cache<Key: Hashable, Value> {
private let wrapped = NSCache<WrappedKey, Entry>()
private let dateProvider: () -> Date
private let entryLifetime: TimeInterval
private let keyTracker = KeyTracker()
@karthikAdaptavant
karthikAdaptavant / singleton.dart
Created Apr 7, 2020 — forked from theburningmonk/singleton.dart
Using Dart's factory constructor feature to implement the singleton pattern
View singleton.dart
class MyClass {
static final MyClass _singleton = new MyClass._internal();
factory MyClass() {
return _singleton;
}
MyClass._internal() {
... // initialization logic here
}
View FlagService.swift
import UIKit
// MARK: Cache Service
struct FlagService {
let key: String
let bufferTime: Double
var canProcess: Bool {
let buffer: Double = bufferTime * 60 * 60
View AppStoryboard.swift
import UIKit
/*
let greenScene = GreenVC.instantiate(fromAppStoryboard: .Main)
let greenScene = AppStoryboard.Main.viewController(viewControllerClass: GreenVC.self)
let greenScene = AppStoryboard.Main.instance.instantiateViewController(withIdentifier: GreenVC.storyboardID)
*/
// MARK: Storyboard
protocol StoryboardIdentifiable {
View ResultType.swift
enum Result<Value, Error: Swift.Error> {
case success(Value)
case failure(Error)
}
enum ApiError: Error {
case none
var desc: String {
return "this is desc"
}
View Cache.swift
import Foundation
public struct Cache<ValueType> {
typealias KeyType = String
private class Box<T>: NSObject {
let value: T
init(_ value: T) {
self.value = value
super.init()
}
View GenericCache.swift
private class ObjectWrapper {
let value: Any
init(_ value: Any) {
self.value = value
}
}
private class KeyWrapper<KeyType: Hashable>: NSObject {
let key: KeyType
View ProgrammerAssertions.swift
//
// ProgrammerAssertions.swift
// Assertions
//
// Created by Mohamed Afifi on 12/20/15.
// Copyright © 2015 mohamede1945. All rights reserved.
//
import Foundation