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 DeinitBlock { | |
| let onDeinit: () -> Void | |
| init(_ block: @escaping () -> Void) { | |
| onDeinit = block | |
| } | |
| deinit { | |
| onDeinit() | |
| } | |
| } |
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
| extension URLSessionDataTask { | |
| var cancellation: DeinitBlock { | |
| return DeinitBlock { [weak self] in | |
| self?.cancel() | |
| } | |
| } | |
| } |
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 URLImageTableViewCell: UITableViewCell { | |
| @IBOutlet weak var urlImageView: UIImageView! | |
| var urlImageLoader: DeinitBlock? | |
| // new task is created, old task cancelled automatically | |
| func setImage(url: URL) { | |
| urlImageLoader = urlImageView.setCachedImage(url: url) | |
| } | |
| } |
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
| extension Timer { | |
| var invalidation: DeinitBlock { | |
| return DeinitBlock { [weak self] in | |
| self?.invalidate() | |
| } | |
| } | |
| } |
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 CoreData | |
| public final class CoreDataStack { | |
| public let persistentContainer: NSPersistentContainer | |
| public init(_ persistentContainer: NSPersistentContainer) { | |
| self.persistentContainer = persistentContainer | |
| } | |
| public private(set) lazy var mainContext: NSManagedObjectContext = { |
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
| extension NSManagedObjectContext { | |
| func performTask(_ block: @escaping (NSManagedObjectContext) -> Void) { | |
| perform { [unowned self] in | |
| block(self) | |
| } | |
| } | |
| } |
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
| extension NSFetchedResultsController { | |
| var sectionCount: Int { | |
| return sections?.count ?? 0 | |
| } | |
| } |
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
| extension NSFetchedResultsController { | |
| @objc func entity(at row: Int) -> ResultType { | |
| object(at: IndexPath(item: row, section: 0)) | |
| } | |
| } |
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 FetchedData<T: NSFetchRequestResult> { | |
| let controller: NSFetchedResultsController<T> | |
| init(_ controller: NSFetchedResultsController<T>) { | |
| self.controller = controller | |
| } | |
| } |
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
| extension FetchedData { | |
| subscript(_ indexPath: IndexPath) -> T { | |
| return controller.object(at: indexPath) | |
| } | |
| } |
OlderNewer