Skip to content

Instantly share code, notes, and snippets.

View karigrooms's full-sized avatar

Kari Grooms karigrooms

View GitHub Profile
@karigrooms
karigrooms / blog--observableobject+protocols--cuckoo-workaround-option-2.swift
Last active November 15, 2021 16:41
Blog: ObservableObjects and Protocols - Use type erasure to workaround Cuckoo mocking issue
// Copyright 2021 Expedia, Inc.
// SPDX-License-Identifier: Apache-2.0
import Combine
protocol PriceRequesting {
var price: Price? { get }
var pricePublisher: AnyPublisher<Price?, Never> { get }
@karigrooms
karigrooms / blog--observableobject+protocols--cuckoo-workaround-option-1.swift
Last active November 15, 2021 16:41
Blog: ObservableObjects and Protocols - Use Combine explicitly to reference Published to workaround Cuckoo mocking issue
// Copyright 2021 Expedia, Inc.
// SPDX-License-Identifier: Apache-2.0
import Combine
protocol PriceRequesting {
var price: Price? { get }
var priceValue: Combine.Published<Price?> { get }
@karigrooms
karigrooms / blog--observableobject+protocols--observableobject-generic.swift
Last active November 15, 2021 16:41
Blog: ObservableObjects and Protocols - Protocol with generic type in SwiftUI
// Copyright 2021 Expedia, Inc.
// SPDX-License-Identifier: Apache-2.0
import SwiftUI
struct PriceView<PriceObservable>: View where PriceObservable: PriceRequesting {
@ObservedObject var pricing: PriceObservable
var body: some View {
@karigrooms
karigrooms / blog--observableobject+protocols--protocol-in-uikit.swift
Last active November 15, 2021 16:42
Blog: ObservableObjects and Protocols - Protocol usage in UIKit
// Copyright 2021 Expedia, Inc.
// SPDX-License-Identifier: Apache-2.0
import Combine
import UIKit
class DemoController: UIViewController {
private let pricing: PriceRequesting
@karigrooms
karigrooms / blog--observableobject+protocols--observableobject-in-uikit.swift
Last active November 15, 2021 16:42
Blog: ObservableObjects and Protocols - ObservableObject in UIKit
// Copyright 2021 Expedia, Inc.
// SPDX-License-Identifier: Apache-2.0
import Combine
import UIKit
class DemoController: UIViewController {
private let pricing: PricingProvider
@karigrooms
karigrooms / blog--observableobject+protocols--protocol-in-swiftui.swift
Last active November 15, 2021 16:42
Blog: ObservableObjects and Protocols - Protocol in SwiftUI
// Copyright 2021 Expedia, Inc.
// SPDX-License-Identifier: Apache-2.0
import SwiftUI
struct PriceView: View {
@State private var price: Price?
let pricing: PriceRequesting
@karigrooms
karigrooms / blog--observableobject+protocols--protocol-no-observableobject.swift
Last active November 15, 2021 16:43
Blog: ObservableObjects and Protocols - Protocol without extending ObservableObject
// Copyright 2021 Expedia, Inc.
// SPDX-License-Identifier: Apache-2.0
// Before
protocol PriceRequesting: ObservableObject {
// ...
}
class PricingProvider: PriceRequesting {
// ...
@karigrooms
karigrooms / blog--observableobject+protocols--protocol-published.swift
Last active November 15, 2021 16:43
Blog: ObservableObjects and Protocols - Protocol with Published properties
// Copyright 2021 Expedia, Inc.
// SPDX-License-Identifier: Apache-2.0
import Combine
protocol PriceRequesting: ObservableObject {
var price: Price? { get }
var priceValue: Published<Price?> { get }
@karigrooms
karigrooms / blog--observableobject+protocols--protocol-no-published.swift
Last active November 15, 2021 16:43
Blog: ObservableObjects and Protocols - Protocol with @published
// Copyright 2021 Expedia, Inc.
// SPDX-License-Identifier: Apache-2.0
import Combine
protocol PriceRequesting: ObservableObject {
var price: Price? { get }
func fetch()
@karigrooms
karigrooms / blog--observableobject+protocols--typical-usage-view.swift
Last active November 15, 2021 16:44
Blog: ObservableObjects and Protocols - Typical usage of ObservableObject in SwiftUI
// Copyright 2021 Expedia, Inc.
// SPDX-License-Identifier: Apache-2.0
import SwiftUI
struct PriceView: View {
@ObservedObject var pricing: PricingProvider
var body: some View {