@Published property wrapper not working on subclass of ObservableObject

Finally figured out a solution/workaround to this issue. If you remove the property wrapper from the subclass, and call the baseclass objectWillChange.send() on the variable the state is updated properly. NOTE: Do not redeclare let objectWillChange = PassthroughSubject<Void, Never>() on the subclass as that will again cause the state not to update properly. I hope … Read more

How to configure ContextMenu buttons for delete and disabled in SwiftUI?

All of the asked situations are now supported in iOS 15 Destructive: (works from iOS 15) Set .destructive as the role argument of the button: Button(role: .destructive) { // 👈 This argument // delete something } label: { Label(“Delete”, systemImage: “trash”) } Disabled: (works from iOS 14.2) Add .disabled modifier to the button. Button { … Read more

How to change the colors of a segment in a UISegmentedControl in iOS 13?

As of iOS 13b3, there is now a selectedSegmentTintColor on UISegmentedControl. To change the overall color of the segmented control use its backgroundColor. To change the color of the selected segment use selectedSegmentTintColor. To change the color/font of the unselected segment titles, use setTitleTextAttributes with a state of .normal/UIControlStateNormal. To change the color/font of the … Read more

SwiftUI @State and .sheet() ios13 vs ios14

Your code have expectation of view update/creation order, but in general it is undefined (and probably changed in iOS 14). There is explicit way to pass information inside sheet – use different sheet creator, ie. .sheet(item:… Here is working reliable example. Tested with Xcode 12 / iOS 14 struct ContentView: View { @State private var … Read more

SwiftUI @Binding Initialize

When you use your LoggedInView in your app you do need to provide some binding, such as an @State from a previous view or an @EnvironmentObject. For the special case of the PreviewProvider where you just need a fixed value you can use .constant(false) E.g. #if DEBUG struct LoggedInView_Previews : PreviewProvider { static var previews: … Read more

Programmatically detect Tab Bar or TabView height in SwiftUI

As bridge to UIKit is officially allowed and documented, it is possible to read needed information from there when needed. Here is possible approach to read tab bar height directly from UITabBar // Helper bridge to UIViewController to access enclosing UITabBarController // and thus its UITabBar struct TabBarAccessor: UIViewControllerRepresentable { var callback: (UITabBar) -> Void … Read more

How to change the status bar background color and text color on iOS 13?

You can add some conditions or use first one. Just create some extension for UIApplication. extension UIApplication { var statusBarUIView: UIView? { if #available(iOS 13.0, *) { let tag = 38482 let keyWindow = UIApplication.shared.windows.filter {$0.isKeyWindow}.first if let statusBar = keyWindow?.viewWithTag(tag) { return statusBar } else { guard let statusBarFrame = keyWindow?.windowScene?.statusBarManager?.statusBarFrame else { return … Read more