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
| protocol Reusable { | |
| func prepareForReuse() | |
| } |
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 UITableViewCell: UIView, Reusable { | |
| func prepareForReuse() { } | |
| } |
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 ObjectPool<T: Reusable> { | |
| private let maxElementCount: Int | |
| private let factory: () -> T | |
| public init(maxElementCount: Int, factory: @escaping () -> T) { | |
| self.factory = factory | |
| self.maxElementCount = maxElementCount | |
| } | |
| } |
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 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 | |
| } | |
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
| func dequeueReusableCell(withIdentifier identifier: String) -> UITableViewCell { | |
| return pool.draw() | |
| } |
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
| func handleDidEndDisplayingCell(_ cell: UITableViewCell, forRowAt indexPath: IndexPath) { | |
| delegate.tableView(_ tableView: self, didEndDisplaying cell: cell, forRowAt indexPath: indexPath) | |
| pool.release(cell) | |
| } |
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 AppDefaults { | |
| static let shared = AppDefaults() | |
| private init() { | |
| //Private initialization to be sure that only one instance is created. | |
| } | |
| } |
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 NotificationName { | |
| case emailChangeNotification | |
| } | |
| protocol StateChangeObserver : class { | |
| func didChange(_ notification: NotificationName, value: String) | |
| } | |
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 Observer: UIViewController, StateChangeObserver { | |
| let loginData = LoginData() | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| loginData.observer = self | |
| } | |
| func didChange(_ notification: NotificationName, value: String) { | |
| if notification == .emailChangeNotification { |
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 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") | |
| } | |
| } |