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
| struct Person { | |
| let name: String | |
| let age: Int | |
| } | |
| let persons = [ | |
| Person(name: "Pera", age: 20), | |
| Person(name: "Mika", age: 30), | |
| Person(name: "Laza", age: 40) | |
| ] |
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
| struct Person { | |
| let name: String | |
| let age: Int | |
| } | |
| struct Payment { | |
| let currency: String | |
| let amount: Double | |
| } |
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 | |
| // MARK: - typed predicate types | |
| public protocol TypedPredicateProtocol: NSPredicate { associatedtype Root } | |
| public final class CompoundPredicate<Root>: NSCompoundPredicate, TypedPredicateProtocol {} | |
| public final class ComparisonPredicate<Root>: NSComparisonPredicate, TypedPredicateProtocol {} | |
| // MARK: - compound operators |
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 GenericCache<H: Hashable, V: AnyObject> { | |
| let nsCache = NSCache<AnyObject, V>() | |
| subscript(_ h: H) -> V? { | |
| get { | |
| return nsCache.object(forKey: h as AnyObject) | |
| } | |
| set { | |
| if let v = newValue { | |
| nsCache.setObject(v, forKey: h as AnyObject) | |
| } else { |
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) | |
| } | |
| } |
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 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
| 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 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
| import CoreData | |
| public final class CoreDataStack { | |
| public let persistentContainer: NSPersistentContainer | |
| public init(_ persistentContainer: NSPersistentContainer) { | |
| self.persistentContainer = persistentContainer | |
| } | |
| public private(set) lazy var mainContext: NSManagedObjectContext = { |