Skip to content

Instantly share code, notes, and snippets.

View Arrlindii's full-sized avatar

Arlind Aliu Arrlindii

View GitHub Profile
protocol Reusable {
func prepareForReuse()
}
class UITableViewCell: UIView, Reusable {
func prepareForReuse() { }
}
class ObjectPool<T: Reusable> {
private let maxElementCount: Int
private let factory: () -> T
public init(maxElementCount: Int, factory: @escaping () -> T) {
self.factory = factory
self.maxElementCount = maxElementCount
}
}
class ObjectPool<T: Reusable> {
private let maxElementCount: Int
private let factory: () -> T
var elements = [T]()
public init(maxElementCount: Int, factory: @escaping () -> T) {
self.factory = factory
self.maxElementCount = maxElementCount
}
func dequeueReusableCell(withIdentifier identifier: String) -> UITableViewCell {
return pool.draw()
}
func handleDidEndDisplayingCell(_ cell: UITableViewCell, forRowAt indexPath: IndexPath) {
delegate.tableView(_ tableView: self, didEndDisplaying cell: cell, forRowAt indexPath: indexPath)
pool.release(cell)
}
class AppDefaults {
static let shared = AppDefaults()
private init() {
//Private initialization to be sure that only one instance is created.
}
}
enum NotificationName {
case emailChangeNotification
}
protocol StateChangeObserver : class {
func didChange(_ notification: NotificationName, value: String)
}
class Observer: UIViewController, StateChangeObserver {
let loginData = LoginData()
override func viewDidLoad() {
super.viewDidLoad()
loginData.observer = self
}
func didChange(_ notification: NotificationName, value: String) {
if notification == .emailChangeNotification {
class KeychainService {
func save(_ password: String, for account: String) {
let password = password.data(using: String.Encoding.utf8)!
let query: [String: Any] = [kSecClass as String: kSecClassGenericPassword,
kSecAttrAccount as String: account,
kSecValueData as String: password]
let status = SecItemAdd(query as CFDictionary, nil)
guard status == errSecSuccess else { return print("save error")
}
}