This file contains 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
private class ObservableModel<Observed>: ObservableObject { | |
@Published var observed: Observed? | |
init(publisher: AnyPublisher<Observed, Never>) { | |
publisher | |
.compactMap { $0 } | |
.receive(on: DispatchQueue.main) | |
.assign(to: &$observed) | |
} | |
} |
This file contains 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
func asPublisher<T>(_ flow: CFlow<T>) -> AnyPublisher<T, Never> { | |
return Deferred<Publishers.HandleEvents<PassthroughSubject<T, Never>>> { | |
let subject = PassthroughSubject<T, Never>() | |
let closable = flow.watch { next in | |
if let next = next { | |
subject.send(next) | |
} | |
} | |
return subject.handleEvents(receiveCancel: { | |
closable.close() |
This file contains 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
data class Restaurant(val id: Int, val name: String, val priceCategory: String) | |
data class Reservation(val id: Int, val date: Long, val numberOfGuests: Int) | |
sealed class Response<T> { | |
class Loading<T>: Response<T>() | |
class Failed<T>: Response<T>() | |
data class Success<T>(val data: T): Response<T>() | |
} | |
interface Api { |
This file contains 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
data class Restaurant(val id: Int, val name: String, val priceCategory: String) | |
data class Reservation(val id: Int, val date: Long, val numberOfGuests: Int) | |
sealed class Response<T> { | |
class Loading<T>: Response<T>() | |
class Failed<T>: Response<T>() | |
data class Success<T>(val data: T): Response<T>() | |
} | |
interface Api { |
This file contains 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 Filter { | |
/// Allows filtering of non sequence types. | |
/// | |
/// let label = UILabel().then { | |
/// $0.textAlignment = .Center | |
/// $0.textColor = UIColor.blackColor() | |
/// $0.text = "Hello, World!" | |
/// } | |
public func filter(@noescape condition: Self -> Bool) -> Self? { |
This file contains 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 DigitsKit | |
import PromiseKit | |
extension Digits { | |
public func authenticateWithCompletion() -> Promise<DGTSession> { | |
return Promise(resolver: authenticateWithCompletion) | |
} |
This file contains 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 Double { | |
var operatingSystemIsSameOrHigher: Bool { | |
let major = Int(self) | |
let minor = Int(round((self - Double(major)) * 10)) | |
let version = NSOperatingSystemVersion(majorVersion: major, minorVersion: minor, patchVersion: 0) | |
return NSProcessInfo().isOperatingSystemAtLeastVersion(version) | |
} | |
var operatingSystemIsLower: Bool { |
NewerOlder