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 | |
| extension UIImage { | |
| func compress(maxKb: Double) -> Data? { | |
| let quality: CGFloat = maxKb / self.sizeAsKb() | |
| let compressedData: Data? = self.jpegData(compressionQuality: quality) | |
| return compressedData | |
| } |
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
| // USAGE | |
| collectionView.register([CELL_CLASS_NAME.self]) | |
| func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | |
| let cell: CELL_CLASS_NAME = collectionView.dequeueReusableCell(indexPath: indexPath) | |
| } | |
| // USAGE | |
| import UIKit |
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 RxCocoa | |
| import RxSwift | |
| class ListViewModel { | |
| // MARK: Properties | |
| let coins: BehaviorRelay<[Coin]> = .init(value: []) | |
| func refreshCoins() { |
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 RxSwift | |
| import RxCocoa | |
| class ListController: UITableViewController { | |
| // MARK: Properties | |
| private let searchController: UISearchController = { | |
| let controller: UISearchController = UISearchController() |
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 Foundation | |
| class ListViewModel { | |
| // MARK: Properties | |
| var coins: [Coin] = [] | |
| var coinsDidRefresh: (() -> Void)? | |
| var coinsCouldNotRefresh: (() -> Void)? |
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 | |
| class ListController: UITableViewController { | |
| // MARK: Properties | |
| private let searchController: UISearchController = { | |
| let controller: UISearchController = UISearchController() | |
| controller.searchBar.placeholder = "Search" | |
| controller.obscuresBackgroundDuringPresentation = false |
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 Foundation | |
| protocol ListDelegate { | |
| func coinsDidRefresh() | |
| func coinsCouldNotRefresh() | |
| } | |
| class ListViewModel { | |
| // MARK: Properties |
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 | |
| class ListController: UITableViewController { | |
| // MARK: Properties | |
| private let searchController: UISearchController = { | |
| let controller: UISearchController = UISearchController() | |
| controller.searchBar.placeholder = "Search" | |
| controller.obscuresBackgroundDuringPresentation = false |
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
| if let userId: String = KeychainManager.shared["userId"], !userId.isEmpty { | |
| // found an userId, which means the user already has opened the app before | |
| // next step: open the home screen or whatever you want | |
| } else { | |
| // the user launches the app for the first time | |
| let newUserId = uniqueId(length: 10) | |
| KeychainManager.shared["userId"] = newUserId | |
| // next step: open the home screen or whatever you want | |
| } |
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
| KeychainManager.shared["email"] = "[email protected]" |