How to fix “Read-Write-Data Sandbox: error when using Mac Catalyst

MasterChief96, you are not alone. Here is my setup: MacOS 10.15.3 Xcode 11.4.1 I create a brand new SwiftUI “Hello World” project, enable Mac as a target device, a.k.a. Catalyst. I set the iOS deployment target to 13.2 (otherwise I get a MacOS runtime error saying I need Catalina 10.15.4) Set the scheme to “My … Read more

@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

addSubview SwiftUI View to UIKit UIView in Swift

Step 1: Create instances of UIHostingController by using SwiftUI View struct ContentView : View { var body: some View { VStack { Text(“Test”) Text(“Test2”) } } } var child = UIHostingController(rootView: ContentView()) Step 2: Add instance of UIHostingController as a child view controller to Any UIKit ViewController var parent = UIViewController() child.view.translatesAutoresizingMaskIntoConstraints = false child.view.frame … 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

‘statusBarOrientation’ was deprecated in iOS 13.0 when attempting to get app orientation

Swift 5, iOS 13, but compatible with older versions of iOS: extension UIWindow { static var isLandscape: Bool { if #available(iOS 13.0, *) { return UIApplication.shared.windows .first? .windowScene? .interfaceOrientation .isLandscape ?? false } else { return UIApplication.shared.statusBarOrientation.isLandscape } } } Usage: if (UIWindow.isLandscape) { print(“Landscape”) } else { print(“Portrait”) }