Post

Replies

Boosts

Views

Activity

Reply to navigationTitle with menu
In beta 1, navigationTitle(_:actions:) was how you would set the menu's actions. In beta 2, a new modifier was added for this instead. It was called toolbarTitleActions(actions:). As of beta 3, you will have to use the renamed toolbarTitleMenu(content:) modifier, like this: .toolbarTitleMenu { MyPrintButton() } Note: the menu will only show when the navigation title display mode is .inline.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to SwiftUI slowly adoption
What they actually said during the talk was this: ... if you're new to our platforms or if you're starting a brand-new app, the best way to build an app is with Swift and SwiftUI. Features can be added to existing apps, and Apple is trying to slowly incorporate SwiftUI into UIKit (and other platform-equivalent frameworks), but the orignial statement is aimed at people starting with Swift and learning to build apps with SwiftUI. Companies with apps can still use UIKit (and similar) and incrementally adopt SwiftUI, but don't have to restructure everything, yet.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to Handling a single window app on MacOS with Swift
The first point can easily be solved through the use of a custom class conforming to the NSApplicationDelegate, implemented like this: class AppDelegate: NSObject, NSApplicationDelegate {     func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {         return true     } } and then adding this to the main app file: @NSApplicationDelegateAdaptor private var appDelegate: AppDelegate On your second point, if needed, you can use the new in Ventura Window struct as the main scene of your app, like this: @main struct SingleWindowApp: App { var body: some Scene { Window("SingleWindow", id: "main") { ContentView() } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to Back supported Navigation-View
NavigationView has only been soft deprecated, so will still function on iOS 16. As for manually back deploying, since NavigationView has been split into two parts but come with added components, such as a path and control over column visibility as well as the new NavigationLink(_:value:) and navigationDestination modifier, it would be quite difficult to accomodate all of this.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to ForEach loop or initializer broken
I have managed to narrow down the issue to the while loop. If it were replaced by a for loop, like this: for _ in 1...20 { numm.append(.random(in: 0...1)) fill += 1 } it would compile and the preview would work. Note: the fill variable is now redundant and won't do anything, unless you use it later on somewhere. After some more debugging, I found that everything in the initialiser has no effect on the two @State variables. You have given them initial values and then tried to change them immediately. Instead, declare them with no value and then set them in the initialiser, like this: @State private var numm: [Int] @State private var fill: Int init() {     _fill = State(initialValue: 0)     var initialNumm: [Int] = []     for _ in 1...20 {         initialNumm.append(.random(in: 0...1))     }     _numm = State(initialValue: initialNumm) } Everything else can be kept the same the way you wrote it.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to Handling single selection action in multi-selection SwiftUI Table
I recently came across a new modifier in macOS Ventura called contextAction(forSelectionType:action:) and seems to do what you are describing. The closure that is run can be used to perform the navigation or whatever you need to happen. I'm currently on Monterey so I don't know how well it works on macOS, but I did try it out on iOS 16. Multi-selection still works when in edit mode, but when edit mode is inactive, tapping on a row performs the closure. Hopefully this helps, and when you try it out on Ventura it works.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to SwiftUI sheet accentColor
The accentColor(_:) modifier is marked as being deprecated with a message saying this: Use the asset catalog’s accent color or tint(_:) instead. Using either of these methods will result in a sheet using this accent colour. If you still want to use accentColor(_:), just reapply this modifier to the sheet content, as a workaround.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to Missing argument for parameter 'images' in call
Missing argument for parameter 'images' in call The problem you have is the ImageCard view has an images parameter that you haven't specified in the NavigationLink label. Consecutive statements on a line must be separated by ';' You also have a closing parenthesis after the NavigationLink which has no matching opening parenthesis; this triggers a syntax error. Replace the contents of your ForEach with this: NavigationLink { LandCard() } label: { ImageCard(images: images) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to Missing argument for parameter 'images' in call
Sorry if I didn't make this clear, but your code from before should look like this: ForEach(ImagesList, id: \.id) { images in NavigationLink { LandCard() } label: { ImageCard(images: images) } } Currently you are showing the ImageCard view twice, the second as a NavigationLink, but I assume that you only need it once. On your second problem, the height of the ImageCard depends on how you create it. Can you show the code for the ImageCard view so that we can understand what is causing the issue?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to Missing argument for parameter 'images' in call
Thank you for sharing all the code. The probable cause of your height issue is that you have wrapped the contents of your ImageCard body in a NavigationView. You don't need to do this as you are already embedding it in one in ContentView. Remove the NavigationView from ImageCard to see if this helps. If it doesn't help, which I'm sure it will, then it would be down to the fact that you are setting an explicit height of 200 to the ZStack in ImageCard. I'm not sure how much this affects things but changing this value to a smaller one might make a difference.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to macOS SwiftUI: Dropdown Menu in a MenuExtraApp not working?
Controls, like menus and pickers with the menu style, don't work when placed in a view of an NSMenuItem. I believe only simple controls and ones with button-like behaviour do. If you need the menu as it is, and because it would be classed as a complex view, I would recommend using a popover instead. Something like this should work: var statusItem: NSStatusItem? var popover: NSPopover? func applicationDidFinishLaunching(_ aNotification: Notification) {     statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)     statusItem?.button?.image = NSImage(systemSymbolName: "gearshape.circle", accessibilityDescription: "Logo")     statusItem?.button?.action = #selector(showPopover)     let hostingViewController = NSHostingController(rootView: MenuExtraView())     popover = NSPopover()     popover?.contentViewController = hostingViewController     popover?.contentSize = .init(width: 350, height: 400)     popover?.behavior = .transient } @objc func showPopover(_ button: NSButton) {     popover?.show(relativeTo: button.bounds, of: button, preferredEdge: .minY) } If you just need a standard menu for your status item instead of a view, then add an item like this: menu.addItem(withTitle: "Quit", action: #selector(NSApp.terminate), keyEquivalent: "q")
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22