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 Publisher { | |
| func awaitSink(cancellable: inout Set<AnyCancellable>) async throws -> Output { | |
| return try await withCheckedThrowingContinuation { continuation in | |
| self.sink { completion in | |
| switch completion { | |
| case .finished: | |
| break |
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 RxCocoa | |
| import RxSwift | |
| extension Reactive where Base: UIImageView { | |
| func image(withDuration: TimeInterval) -> Binder<UIImage?> { | |
| return Binder(base) { imageView, image in | |
| // needed to avoid "Value of type 'UIView' has no member 'image'" |
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 RxCocoa | |
| import RxSwift | |
| class ViewController: UIViewController { | |
| @IBOutlet weak var imageView: UIImageView! | |
| @IBOutlet weak var label: UILabel! | |
| @IBOutlet weak var nextButton: UIButton! |
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 | |
| import RxSwift | |
| import RxCocoa | |
| class ViewModel { | |
| private let imageRelay: BehaviorRelay<UIImage?> = BehaviorRelay(value: nil) | |
| private let labelTextRelay: BehaviorRelay<String?> = BehaviorRelay(value: nil) | |
| var buttonTapRelay = PublishRelay<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
| class MigrationPolicy: NSEntityMigrationPolicy { | |
| override func createDestinationInstances(forSource sInstance: NSManagedObject, in mapping: NSEntityMapping, manager: NSMigrationManager) throws { | |
| // MARK: 1 - Check if it is a person | |
| if sInstance.entity.name == "Person" { | |
| // MARK: 2 - fetch the values | |
| let firstName = sInstance.primitiveValue(forKey: "firstname") as? String | |
| let lastName = sInstance.primitiveValue(forKey: "lastname") as? String | |
| let age = sInstance.primitiveValue(forKey: "age") as? 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
| // we will test the migration from version 1 to 2. the names of a person changed. | |
| func testHeavyWeightMigration() { | |
| // MARK: 1 read and load the old model | |
| let oldModelURL = Bundle(for: AppDelegate.self).url(forResource: "CoreDataMigrationGuide.momd/CoreDataMigrationGuide 3", withExtension: "mom")! | |
| let oldManagedObjectModel = NSManagedObjectModel(contentsOf: oldModelURL) | |
| XCTAssertNotNil(oldManagedObjectModel) | |
| let coordinator = NSPersistentStoreCoordinator(managedObjectModel: oldManagedObjectModel!) | |
| try! coordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: nil) |
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
| // we will test the migration from version 1 to 2. the names of a person changed. | |
| func testHeavyWeightMigration() { | |
| // MARK: 1 - read and load the old model | |
| let oldModelURL = Bundle(for: AppDelegate.self).url(forResource: "CoreDataMigrationGuide.momd/CoreDataMigrationGuide 2", withExtension: "mom")! | |
| let oldManagedObjectModel = NSManagedObjectModel(contentsOf: oldModelURL) | |
| XCTAssertNotNil(oldManagedObjectModel) | |
| let coordinator = NSPersistentStoreCoordinator(managedObjectModel: oldManagedObjectModel!) | |
| try! coordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: nil) |
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
| // we will test the migration from version 1 to 2. the names of a person changed. | |
| func testLightWeightMigration() { | |
| // MARK: 1 - read and load the old model | |
| let oldModelURL = Bundle(for: AppDelegate.self).url(forResource: "CoreDataMigrationGuide.momd/CoreDataMigrationGuide", withExtension: "mom")! | |
| let oldManagedObjectModel = NSManagedObjectModel(contentsOf: oldModelURL) | |
| XCTAssertNotNil(oldManagedObjectModel) | |
| let coordinator = NSPersistentStoreCoordinator(managedObjectModel: oldManagedObjectModel!) | |
| try! coordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: nil) |