Skip to content

Instantly share code, notes, and snippets.

View mbrandonw's full-sized avatar

Brandon Williams mbrandonw

View GitHub Profile
received action:
AppAction.currentGame(
GameFeatureAction.game(
GameAction.tap(
UIGestureRecognizer.State.ended,
1.1.0@top,
)
)
)
AppState(
import Combine
class VM: ObservableObject {
@Published var int = 0
}
let vm = VM()
_ = vm.$int.sink { value in
print("Current value", value)
protocol SomeProtocol {
func foo() -> Int?
}
struct Live: SomeProtocol {
func foo() -> Int? {
// do some work to return an integer
}
}
import Combine
import ComposableArchitecture
import UserNotifications
public struct UserNotificationClient {
public var add: (UNNotificationRequest) -> Effect<Void, Error>
public var delegate: Effect<DelegateEvent, Never>
public var getNotificationSettings: Effect<Notification.Settings, Never>
public var removeDeliveredNotificationsWithIdentifiers: ([String]) -> Effect<Never, Never>
public var removePendingNotificationRequestsWithIdentifiers: ([String]) -> Effect<Never, Never>
struct StoreManagerClient {
var load: (String) -> AnyPublisher<(Data, URLResponse), URLError>
func load<Output: Decodable>(objectID: String) -> AnyPublisher<Output, Error> {
self.load(objectId)
.decode(type: Output.self, decoder: JSONDecoder())
.eraseToAnyPublisher()
}
}

FB8379503

Sheet modifier on nested view does not work

If a .sheet modifier is used on a child view while the parent view is also using a .sheet modifier, then the child view’s sheet will never appear:

struct ContentView: View {
  @State var isPresented1 = false
  @State var isPresented2 = false

FB7828757

LocalizedStringKey equatable doesn't work as expected

It can be useful to assert again LocalizedStringKey in unit tests. Sometimes there is significant logic that goes into constructing a localized string and so it’s good to be able to write tests against that.

However, as soon as you apply some formatting to a string it seems to break equatability:

LocalizedStringKey("\(1)") == LocalizedStringKey("\(1)") // false

FB8130464

I have found an erroneous invocation of onDisappear in a particular view hierarchy. If you have a NavigationView wrapping a Form, which has a NavigationLink that drills down to a Form, then the inner most Form will have its onDisappear invoked when the view appears.

Here is a code sample that reproduces it:

struct ContentView: View {
  var body: some View {
 NavigationView {

FB7867609

Consider the following code:

class ViewModel: ObservableObject {
  @Published private(set) var value = 0
}

let vm = ViewModel()
import SwiftUI
struct ContentView: View {
@State var isFavorite = false
var body: some View {
FavoriteComponent(id: 42, isFavorite: self.$isFavorite)
}
}