Post

Replies

Boosts

Views

Activity

Reply to Swift Combine API client; return Future or AnyPublisher?
I don't have a definite answer on what the best practice is, but have wondered the same thing. In the past, I would return a Future. Now, I always return type-erased AnyPublisher. I find it keeps the interface more general, seems cleaner (standard) and, like you said, often it's easier to work. Besides, the type-erased Future returned as AnyPublisher is still going to finish after one output.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’22
Reply to State loops in UIViewRepresentable
Don't pass the SwiftUI View to the coordinator. It is a struct and many copies of it are made as the screen is redrawn. Instead put the center location in an ObservableObject pass that and additionally, if you need it, a reference to the UIView itself (it is an object and only one copy is created. In your case you don't need use it because the delegate gives you the reference to the UIView, but often you do need your own reference). So make something like class MapState: ObservableObject { @Published var centre: CLLocationCoordiate2D? }. Have the SwiftUI View hold that, either as StateObject, ObservedObject or EnvironmentObject depending on where the object is made. Pass a reference of that object to the Coordinator. When the delegate calls, update that property and the @Published should send that back to the SwiftUI view to update.
Topic: UI Frameworks SubTopic: UIKit Tags:
Apr ’21
Reply to Swift Combine API client; return Future or AnyPublisher?
I don't have a definite answer on what the best practice is, but have wondered the same thing. In the past, I would return a Future. Now, I always return type-erased AnyPublisher. I find it keeps the interface more general, seems cleaner (standard) and, like you said, often it's easier to work. Besides, the type-erased Future returned as AnyPublisher is still going to finish after one output.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Xcode 13 + MacOS Big Sur (11.6) + M1 Chip + compile time
Don't have a solution, but I'm experiencing a similar thing with the same setup. Compiling the files seems ok, but other steps are getting stuck often.
Replies
Boosts
Views
Activity
Oct ’21
Reply to passing nil to `perferredColorScheme` instead of light/dark
Awesome, I'm using the regular 12.4 release and this feature can wait. Thanks @BabyJ.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’21
Reply to State loops in UIViewRepresentable
Don't pass the SwiftUI View to the coordinator. It is a struct and many copies of it are made as the screen is redrawn. Instead put the center location in an ObservableObject pass that and additionally, if you need it, a reference to the UIView itself (it is an object and only one copy is created. In your case you don't need use it because the delegate gives you the reference to the UIView, but often you do need your own reference). So make something like class MapState: ObservableObject { @Published var centre: CLLocationCoordiate2D? }. Have the SwiftUI View hold that, either as StateObject, ObservedObject or EnvironmentObject depending on where the object is made. Pass a reference of that object to the Coordinator. When the delegate calls, update that property and the @Published should send that back to the SwiftUI view to update.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Apr ’21