Posts

Post marked as solved
1 Replies
0 Views
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.
Post not yet marked as solved
2 Replies
0 Views
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.
Post marked as solved
2 Replies
0 Views
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() } } }
Post not yet marked as solved
6 Replies
0 Views
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.
Post not yet marked as solved
1 Replies
0 Views
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.
Post not yet marked as solved
2 Replies
0 Views
You can detect when the user taps on the specified tab with this: // add to the TabView .onChange(of: selectedTab) { [selectedTab] newTab in if newTab == "OpenLinkTab" { self.selectedTab = selectedTab // return to previously selected tab // open URL here         let url = URL(string: "https://www.apple.com")! openURL(url) } } When the tab item is tapped, it will look like a regular button press as the tab view switches back to the previously selected tab. This is when you can open the link providing the behaviour you want. This solution would be similar to implementing the UITabBarControllerDelegate.tabBarController(_:shouldSelect:) delegate method and returning false (in a UIKit app).
Post not yet marked as solved
3 Replies
0 Views
New in iOS 16 beta 3, two new modifiers! You can use them to set a background colour for a list: List { ... } .scrollContentBackground(Color.red) // using .red results in an error or set a custom background view: List { ... } .scrollContentBackground(.hidden) .background {     Image(systemName: "list.bullet")         .resizable()         .scaledToFit()         .padding() }
Post not yet marked as solved
6 Replies
0 Views
New in iOS 16 beta 3, two new modifiers! You can use them to set a background colour for a list: List { ... } .scrollContentBackground(Color.red) // using .red results in an error or set a custom background view: List { ... } .scrollContentBackground(.hidden) .background {     Image(systemName: "list.bullet")         .resizable()         .scaledToFit()         .padding() }
Post marked as solved
4 Replies
0 Views
I'm assuming you're using SwiftUI since that's what you tagged the question with. If so, your views should automatically be placed to fit in the safe area. Using the ignoresSafeArea(_:edges:) modifier, well, ignores the safe area, so expanding to fill the whole screen. If you want your views to fill the entire space inside of the safe area, you can use a frame modifier like this: .frame(maxWidth: .infinity, maxHeight: .infinity) If you explicitly want the top and bottom safe area inset values, then you can wrap your view in a GeometryReader and access the values like this: GeometryReader { geoProxy in let topInset = geoProxy.safeAreaInsets.top let bottomInset = geoProxy.safeAreaInsets.bottom ... }
Post not yet marked as solved
1 Replies
0 Views
The variable Produkt is of type Array<ScannProdukt>. In the addRow method, you are appending the value stored in ScannedCode to this array which is of type String. The error comes from the fact that the array expects a value of type ScannProdukt to be appended, but instead got a value of type String. You would need to use the ScannedCode property to create a ScannProdukt that can be appended to the Produkt array.
Post marked as solved
1 Replies
0 Views
Move the @State property wrapper from the selected variable in the mySession struct to the sessions array. You can then pass a binding directly into the Toggle, like this: ForEach($sessions) { $session in Toggle(isOn: $session.selected) { Text(session.name) } }
Post marked as solved
2 Replies
0 Views
Just use the new initialiser for Image like this: Image(systemName: "wifi", variableValue: 0.5)
Post not yet marked as solved
1 Replies
0 Views
I'm not really sure what you're asking. If you want to know how to show a different view based on the current selection then you can see the ammended code below: @State var selectedNavigationCategory: NavigationCategory? let navigationCategories = [     NavigationCategory(id: UUID(), name: "One", sfSymbol: "circle"),     NavigationCategory(id: UUID(), name: "Two", sfSymbol: "circle.fill") ] var body: some View {     NavigationSplitView {         List(navigationCategories, selection: $selectedNavigationCategory) { category in             NavigationLink(value: category) {                 Label(category.name, systemImage: category.sfSymbol)             }         }     } detail: {         ZStack { // workaround in beta 2             if let selectedNavigationCategory {                 // Something has been selected // Show the corresponding view for this                 Text("You selected \(selectedNavigationCategory.name)")             } else {                 // Nothing is selected // Placeholder text                 Text("Select something")             }         }     } }
Post marked as solved
4 Replies
0 Views
A lot of people have been experiencing different behaviours with the new Layout API and they each have different solutions. Resolved in iOS & iPadOS 16 beta 2, passing multiple children to a custom Layout now compiles. This means that a Group or another container is no longer required. The other issue arises from how the layout views are created under the hood. Two solutions for this are either wrapping the layout name in parentheses: (CustomLayout()) { Text("Hello, World") Text("Hello, World") } or creating an initialiser for the custom Layout that accepts no parameters: init() {} ... CustomLayout { Text("Hello, World") Text("Hello, World") }
Post marked as solved
1 Replies
0 Views
Trying adding this to the buttons: .highPriorityGesture(DragGesture())