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
enum Root {} | |
enum ChatRooms {} | |
enum ChatRoom {} | |
enum Messages {} | |
struct Message: Codable { | |
// Our Message entity | |
var header: String | |
var body: 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
// So from the Objc.io talk, we learn about a way of representing filesystem paths that can point to either files or directories. | |
// Internally, these are represented as an array of path elements. Let's do that too: | |
public struct Path<Element> { | |
public struct Collection { | |
private var components: [String] | |
public func child(_ key: String) -> Path<Element> { | |
return append(key) | |
} |
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
enum Root {} | |
enum ChatRoom {} | |
struct Message: Codable { | |
var header: String | |
var body: String | |
} | |
struct Configuration: Codable { | |
// Our actual Configuration entity |
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
// A small wrapper so that we prevent the user from calling collection observation with .value | |
public enum CollectionEventType { | |
case childAdded, childChanged, childRemoved | |
var firebaseEventType: DataEventType { | |
switch self { | |
case .childAdded: | |
return .childAdded | |
case .childChanged: | |
return .childChanged | |
case .childRemoved: |
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 Reactive where Base: DatabaseQuery { | |
func observeSingleEvent<T>(of type: DataEventType) -> Single<T> where T: Decodable { | |
return Single.create { single in | |
self.base.observeSingleEvent(of: type, with: { (result: DecodeResult<T>) in | |
single(result.asSingleEvent) | |
}) | |
return Disposables.create() | |
} | |
} |
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
public class FirebaseService { | |
private let rootRef: DatabaseReference | |
public init(ref: DatabaseReference) { | |
self.rootRef = ref.root | |
} | |
// MARK: Observing Paths | |
func observeSingleEvent<T>(at path: Path<T>) -> Single<T> | |
where T: Decodable { | |
let ref = rootRef.child(path.rendered) |
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
protocol ResultProtocol { | |
associatedtype WrappedType | |
associatedtype ErrorType | |
var value: WrappedType? { get } | |
var error: ErrorType? { get } | |
} | |
extension Result: ResultProtocol { | |
typealias WrappedType = Value | |
typealias ErrorType = Error |
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 FirebaseDatabase | |
import Foundation | |
import RxSwift | |
protocol ViewModelInputs { | |
func add(message: Message) | |
func update(configuration: Configuration) | |
} | |
protocol ViewModelOutputs { |
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
public class PixelBasedLayoutConstraint: NSLayoutConstraint { | |
override public func awakeFromNib() { | |
super.awakeFromNib() | |
constant /= UIScreen.main.scale | |
} | |
} |
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 SwiftUI | |
struct TextFormatting: ExpressibleByStringLiteral, ExpressibleByStringInterpolation { | |
struct StringInterpolation: StringInterpolationProtocol { | |
var output: Text = Text(verbatim: "") | |
init(literalCapacity: Int, interpolationCount: Int) { | |
// TODO | |
} | |