How to programatically open Settings/Preferences window in a macOS SwiftUI App

By inspecting the app menu, I found this solution: NSApp.sendAction(Selector((“showPreferencesWindow:”)), to: nil, from: nil) I assume that it may not pass App Review for using a private API, though, so less shady alternatives are still welcome. Update: This has actually passed App Review, so I had marked it as the answer. Update 2: For a … Read more

SwiftUI – make sure to publish values from the main thread (via operators like receive(on:)) on model updates

Just put @MainActor before defining your class that is supposed to act in the main thread. And it’s so simple in terms of using new Swift concurrency. @MainActor class DocumentsViewModel: ObservableObject { … } There’s a lot of information about that in new WWDC 2021 videos or articles like that: Using the MainActor attribute to … Read more

SwiftUI – Change TabBar Icon Color

Solution 1 Use renderingMode(.template) struct MainView: View { var body: some View { TabView { LoginView().tabItem { VStack { Text(“Login”) Image(“login”).renderingMode(.template) } } HomeView().tabItem { VStack { Text(“Home”) Image(“home”).renderingMode(.template) } } }.accentColor(.orange) } } Solution 2 Make tabItem type enum TabViewItemType: String { case login = “login” case home = “home” case search = “search” … Read more

How to detect whether targetEnvironment is iPadOS in SwiftUI?

I use this in my code: private var idiom : UIUserInterfaceIdiom { UIDevice.current.userInterfaceIdiom } private var isPortrait : Bool { UIDevice.current.orientation.isPortrait } Then you can do this: var body: some View { NavigationView { masterView() if isPortrait { portraitDetailView() } else { landscapeDetailView() } } } private func portraitDetailView() -> some View { if idiom … Read more

Remove top padding from List

Firstly, I would say that GroupedListStyle is working as intended. On iOS, the grouped list style displays a larger header and footer than the plain style, which visually distances the members of different sections. You say you have tried this, but it does work for me (Xcode 12.5.1): List { … } .onAppear(perform: { UITableView.appearance().contentInset.top … Read more

SwiftUI TextField cursor colour

EDIT: as pointed out below and in the documentation, my original answer (below) is now deprecated and you should use .tint instead. Or if you want all text fields and other UI elements in your app to be the same you can customize your app’s global accentColor. Original answer: Tried it out and .accentColor does … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)