(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| import CoreData | |
| import Foundation | |
| protocol CoreDataManager { | |
| var uiContext: NSManagedObjectContext { get } | |
| func newBackgroundContext() -> NSManagedObjectContext | |
| func performBackgroundTaskOnUI(_ block: @escaping (NSManagedObjectContext) -> Void) | |
| func performBackgroundTask(_ block: @escaping (NSManagedObjectContext) -> Void) | |
| func loadStore(completionHandler: ((Error?) -> Void)?) | |
| } |
| //: [Previous](@previous) | |
| import Foundation | |
| import SwiftUI | |
| import Combine | |
| //: Current Value Subject is a value, a publisher and a subscriber all in one | |
| let currentValueSubject = CurrentValueSubject<Bool, Never>(true) | |
| print(currentValueSubject.value) |
| // Created by Vasily Ulianov on 09.02.17, updated in 2019. | |
| // License: MIT | |
| import Foundation | |
| /// Subclass of `Operation` that adds support of asynchronous operations. | |
| /// 1. Call `super.main()` when override `main` method. | |
| /// 2. When operation is finished or cancelled set `state = .finished` or `finish()` | |
| open class AsynchronousOperation: Operation { | |
| public override var isAsynchronous: Bool { |
| extension Dictionary { | |
| func get(key: Key, defaultValue: Value) -> Value { | |
| /** | |
| Returns the value for the given key (if exists), otherwise returns the default value. | |
| */ | |
| if let value = self[key] { | |
| return value | |
| } else { |
| // | |
| // CollectionViewDataSource.swift | |
| // Khan Academy | |
| // | |
| // Created by Andy Matuschak on 10/14/14. | |
| // Copyright (c) 2014 Khan Academy. All rights reserved. | |
| // | |
| import UIKit |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| import Foundation | |
| extension Array | |
| { | |
| /** Randomizes the order of an array's elements. */ | |
| mutating func shuffle() | |
| { | |
| for _ in 0..<10 | |
| { | |
| sort { (_,_) in arc4random() < arc4random() } |