Post

Replies

Boosts

Views

Activity

SwiftUI equivalent of validateMenuItem(_:)
I am wondering how to validate menu items in SwiftUI (2.0, macOS). Given the following: @main struct MyApp: App {     var body: some Scene {         WindowGroup {             ContentView()         }         .commands {             CommandMenu("DEBUG") {                 Button(action: { }) {                     Text("menu item 1")                 }                 Button(action: { }) {                     Text("menu item 2")                 }             }         }     } } Suppose menu item 1 is conditional and should be shown or hidden depending on the app state. In AppKit we would use NSMenuItemValidation    func validateMenuItem(_ menuItem: NSMenuItem) -> Bool { // validate the menuItem to be shown } to determine if a menu item should be shown/disable/enabled. Question: how can we do menu validation in SwiftUI? From what I have found so far CommandMenu is build *once* and cannot be dynamically adapted to reflect the current AppState. Or am I missing something?
2
0
1.4k
Oct ’20
SwiftUI Splitview: persist view positions
I am creating a SwiftUI 2 app with a HSplitView. The SplitView has several subviews (sidebar - main view - detail view). The user may resize the individual views with the normal split view behavior (dragging the divider bar). I want to persist the user's last used view sizes, so that when the user closes the app and comes back later, the same view layout (view sizes inside the splitview) is presented. How can/should this be achieved? Thanks for your help.
1
0
1k
Oct ’20
SwiftUI listItemTint
Suppose you compose a number of sidebar items using SwiftUI's Outlinegroup:  OutlineGroup(section.children ?? [], children: \.children) { item in ItemRow(item) } View Modifier .listItemTint(.yellow) on the OutlineGroup applies to all of the items in thet group. One cannot use .listItemTint on ItemRow. How to tint just one of the child items with a particular color?
0
0
436
Aug ’20
Provisioning profile process - lacking "do you need additional entitlements" step
The good news: my request for privileged-file-operations entitlements has been approved by Apple. The bad: I cannot find the "Do you need additional entitlements?” page. Explanation: on approval, Apple sent an email with instructions. The first step is to generate a provisioning profile: To use this special entitlement you must create a new provisioning profile in the Certificates, Identifiers & Profiles section of your developer account and select the entitlement after the “Do you need additional entitlements?” page. However, I never get presented the "Do you need additional entitlements" question(!) What I did: log in at developer account go to section "Certificates, Identifiers & Profiles" click "generate a profile" (I had no previous profiles, I am still in development) choose "macOS App Development" select the appropriate Profile Type (mac) App id (myAppID) select (all) my development certificate select (all) my devices enter a Provisioning Profile Name In the last step I only get the option to "Generate" the profile. I would expect the question "Do you need additional entitlements?" first though. Please note that I am new to this. I have not have previous experience with provisioning profiles as I have not published an app before. Please be specific in a solution on how to if this. I would prefer to be pointed to some "step by step" instruction if possible. Help is much appreciated! PS: I have also tried several other options available in the provisioning section, to no avail (and there are way too many permutations possible to figure out which needle in the haystack I am supposed to find). I read the instructions apple points to, but these all deal with issues *after* having concluded the first step.
6
0
7.4k
Jul ’20
How to make SwiftUI List translucent? (macOS!)
SwiftUI List comes with embedded scroll functionalty, which is nice, except...that view has a (white) background at a higher lever than any modifyable view. Result: a background view is layered behind the white background of the scroll view. In the debugger I see that the List encapsulates a Hosting View>View Host>ListCoreScrollView. The latter shows opaque. Thusly, trying to change the background of the List has no effect: the background view will be behind the white scroll view.You can easily try it yourself. Create a list with some random rows.List { ForEach(rows.items)Run the app, then look at the View Debugger: rotate the view and you will see the auto generated while layer in the view hierarchy.My first attempt was setting the background color (to no avail, as described above). I also tried adding a custom ViewModifier. Inside a viewModifier one can set the UITableView.appearance(). However, that is IOS only, it does not work on macOS. Using VisualEffectBackground as described here did not get me anywhere either...The only thing that did yield some result is changing the listStyle. Adding .listStyle(SidebarListStyle()) does result in the background that I like, but has another, even worse, side effect: dragging does not work as needed. (I tried modifying that behavior as well, but that causes a whole range of new issues, so gave up).In the end I have spend many hours trying to change something simple as the (background) color of a List. I want to implement a sidebar that is more like the Finders sidebar (which is not white either). Just repeating to avoid irrelevant answers: macOS platform, not IOS.
3
0
5.5k
Jan ’20