Search results for

column

2,048 results found

Post

Replies

Boosts

Views

Activity

NavigationSplitView
Hello everyone, I am currently trying to implement and test the latest SwiftUI changes with Xcode 16 Beta 3. Now I wanted to create, like in FreeForm, that I have a grid in the detail column with tiles in a NavigationSplitView. If you now press on the tile, a DetailView (in my code its an EmptyView) should open with the zoom effect and in fullscreen so that the NavigationSplitView disappears and the NavigationBar is no longer there. In FreeForm the desired effect is when you create a new board. any tips or hints? struct CanvasGrid: View { @Namespace var namespace; var body: some View { if let project = project { if viewMode == .grid { ScrollView{ LazyVGrid(columns: columns, spacing: 10) { ForEach(sortedCanvases) { canvas in NavigationLink { EmptyView() .navigationTransition( .zoom(sourceID: canvas.id, in: namespace) ) } label: { CanvasTile(canvas: canvas) } .matchedTransitionSource(id: canvas.id, in: namespace) } } .searchable(text: $searchText) .navigationTitle(project.name) } } #P
0
0
471
Jul ’24
Reply to SwiftUI view is not updated properly
Working code snippet: import SwiftUI import SwiftData @main struct MainApp: App { var body: some Scene { WindowGroup { SomeView() } .modelContainer(appContainer) } } struct SomeView: View { @Query private var items: [AItem] var body: some View { ParentView(items: items) } } struct ParentView: View { private var groupedItems: [GroupedAItems] = [] init(items: [AItem]) { Dictionary(grouping: items) { $0.categoryName } .forEach { let groupedItems = GroupedAItems(categoryName: $0.key, items: $0.value) self.groupedItems.append(groupedItems) } } var body: some View { ScrollView { VStack(spacing: 15) { ForEach(groupedItems, id: .self.categoryName) { groupedItems in ChildView(groupedItems) } } } } } struct ChildView: View { public var groupedItems: GroupedAItems @State private var showItems: Bool init(_ groupedItems: GroupedAItems) { self.groupedItems = groupedItems self._showItems = State(initialValue: !groupedItems.completed) print(init, group (groupedItems.categoryName) - items not completed (!groupedItems.complete
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’24
.chartXScale not scaling domain of Chart as expected
Hi, I'm currently wrestling with the .chartXScale(domain:) modifier in order to get my Chart to display correctly. The basics of the Chart look like this. Chart(measurements, id: .timestamp) { measurement in if let total = measurement.production?.total { BarMark( x: .value( Timestamp, measurement.timestamp, unit: .weekOfYear, calendar: .current ), y: .value( Solar production, total ) ) } } As anyone familiar with Charts can see, I sort data into columns based on what week of the year the measurements belong to. Some of them can be null, and when they are, I still want space in the Chart where a BarMark would've been to be taken up, like week number 4 in this example chart (in which I've defaulted all measurements that are null in week 4 to 0, for demonstration purposes): To achieve that, as I understand, I'm meant to use the .chartXScale(domain:) modifier, but when I apply the following modifier... .chartXScale(domain: firstDayOfMonth...firstDayOfNextMonth) ... (where the domain is from the first day
9
0
1.3k
Jul ’24
Really High Energy Use
I'm developing an app where users can select items to add to a screen, similar to creating a Canva presentation or choosing blocks in Minecraft. However, I'm encountering an issue with energy usage. When users click the arrows to browse different items, the energy use spikes significantly. Although it returns to normal after a while, continuous clicking causes the energy use to skyrocket. The images I'm using are 500x500 pixels. Ideally, I would like to avoid caching all the images, as the app might have up to 500 items and caching them all would consume too much memory. I have tried numerous way to avoid this but I just can’t seem to make it work. Would anyone know how to avoid such problem? I have included a picture of the energy use when just opened, and one after like 10 seconds of continuously clicking on an arrow to see more items. Also a picture of how the app looks. struct ContentView: View { struct babyBackground { var littleImage = } @State var firstSet: [babyBackground] = [ babyBackground(littleIm
1
0
769
Jul ’24
Is it possible to use a list-style UICollectionView but have multiple columns?
I'm working on a UICollectionView that has a custom compositional layout with multiple columns. I wanted to add swipe actions to the cells (specifically, a delete action). I knew this was possible because of the existence of trailingSwipeActionsConfigurationProvider but I didn't realize that this is only for list layouts, created with UICollectionViewCompositionalLayout.list. But if I use a list layout, I don't think I have any opportunity to add multiple columns. Do I really have to choose between multiple columns and trailing swipe actions? Or is there some way to get both?
Topic: UI Frameworks SubTopic: UIKit Tags:
0
0
495
Jul ’24
Reply to SwiftUI List OutlineGroup
@JMDelh Have you considered using a two-column navigation split view instead? The selection works but the detail view is updated only when I click the text but not when I click the rest of the row. This results in the detail view not being sync with the list selection. Apply the contentShape(_:eoFill:) and set the maxWidth of to infinity Text((item.description)) .frame(maxWidth: .infinity) .contentShape(Rectangle())
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’24
timeseriesclassifier
After I have a dataframe of data with one column as features with type MLshapedarray and one column of annotations with type Int. How can I convert them to the correct input type for the timeseriesclassifier?
0
0
617
Jul ’24
How to animate NavigationSplitView's detailView column.
Having a traditional 'NavigationSplitView' setup, I am looking for a way to animate it the same as the sidebarView, where there is a button to toggle and it animates by sliding out from the right side of the view, however the closest I have gotten was manipulating the 'navigationSplitViewColumnWidth' but that always results in the view instantly appearing / disappearing. I am using SwiftUI for a MacOS specific app. Here is just a general idea of what I am currently doing, it is by no means a reflection of my real code but serves the purpose of this example. struct ContentView: View { @State private var columnWidth: CGFloat = 300 var body: some View { NavigationSplitView { List { NavigationLink(destination: DetailView(item: Item 1)) { Text(Item 1) } NavigationLink(destination: DetailView(item: Item 2)) { Text(Item 2) } NavigationLink(destination: DetailView(item: Item 3)) { Text(Item 3) } } .navigationTitle(Items) } detail: { VStack { DetailView(item: Select an item) Button(action: toggleColumnWidth) { Text(co
1
0
876
Jun ’24
Reply to Peculiar EXC_BAD_ACCESS, involving sparse matrices
the sparseMatrix function with comments: extension Array where Element == [Double] { // A sparse matrix is a mattrix where all zero's are ommitted. // Normal matrix: Sparse matrix: // 0 1 0 1 // 1 3 0 1 3 // 4 0 2 4 2 // Find the sparse matrix of this matrix. Returns an array of doubles containing the values of the sparse matrix (omitting all zero's) and a SparseMatrixStructure containing information about where the columns start and where the rows start. The values array of the sparse matrix above would be [1, 4, 1, 3, 2]. func sparseMatrix() -> (structure: SparseMatrixStructure, values: [Double]) { let columns = self.transpose() // Get the row indices of the matrix. The row indices of the sparse matrix above would be // [1, 2 column 0 // 0, 1, column 1 // 2] column 2 var rowIndices: [Int32] = columns.map { column in column.indices.compactMap { indexInColumn in if column[indexInColumn] != 0 { return Int32(indexInColumn) } return nil } }.reduce
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’24
Reply to Peculiar EXC_BAD_ACCESS, involving sparse matrices
The SavitzkyGolay class with comments: class SavitzkyGolay { static func coefficients(windowLength: Int, polynomialOrder: Int, derivativeOrder: Int = 0, delta: Int = 1) -> [Double] { // windowLength is the number of coefficients returned by this function. guard windowLength > 0 else { fatalError(windowLength must be positive) } // polynomialOrder is the order of the polynomial used to smooth the noisy data (the coefficients are calculated independently from the noisy data) guard polynomialOrder < windowLength else { fatalError(polynomialOrder must be less than windowLength) } // The derivativeOrder is the order of the derivative to compute. If it is set to zero, the noisy data is smoothed without differentiating. guard derivativeOrder <= polynomialOrder else { return [Double](repeating: 0, count: windowLength) } let (halfWindow, remainder) = windowLength.quotientAndRemainder(dividingBy: 2) var pos = Double(halfWindow) // pos should not be a round number (because otherwise this function won't work
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’24
Peculiar EXC_BAD_ACCESS, involving sparse matrices
Helo all, Currently, I'm working on an iOS app that performs measurement and shows the results to the user in a graph. I use a Savitzky-Golay filter to filter out noise, so that the graph is nice and smooth. However, the code that calculates the Savitzky-Golay coefficients using sparse matrices crashes sometimes, throwing an EXC_BAD_ACCESS. I tried to find out what the problem is by turning on Address Sanitizer and Thread Sanitizer, but, for some reason, the bad access exception isn't thrown when either of these is on. What else could I try to trace back the problem? Thanks in advance, CaS To reproduce the error, run the following: import SwiftUI import Accelerate struct ContentView: View { var body: some View { VStack { Button(Try, action: test) } .padding() } func test() { for windowLength in 3...100 { let coeffs = SavitzkyGolay.coefficients(windowLength: windowLength, polynomialOrder: 2) print(coeffs) } } } class SavitzkyGolay { static func coefficients(windowLength: Int, polynomialOrder: Int, derivativeOr
11
0
1.4k
Jun ’24
Reply to Data storage for a Matrix struct when working with Accelerate
I would also like to mention that running the code below gives me almost identical elapsed times for the matrix array and matrix buffer solutions. So, at least for this case, I'm not seeing any performance differences between the two approaches. func runBenchmark1() { print(Benchmark matrix multiplication) for _ in 1...3 { let tic = Date.now let n = 8_000 let a = Matrix(rows: n, columns: n, fill: 1.5) let b = Matrix(rows: n, columns: n, fill: 2.8) let c = a * b let toc = tic.timeIntervalSinceNow.magnitude let elapsed = String(format: %.4f, toc) print(Elapsed time is (elapsed) sec, first element is (c[0, 0])) } }
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’24
Data storage for a Matrix struct when working with Accelerate
I have a Matrix structure as defined below for working with 2D numerical data in Accelerate. The underlying numerical data in this Matrix struct is stored as an Array. struct Matrix { let rows: Int let columns: Int var data: [T] init(rows: Int, columns: Int, fill: T) { self.rows = rows self.columns = columns self.data = Array(repeating: fill, count: rows * columns) } init(rows: Int, columns: Int, source: (inout UnsafeMutableBufferPointer) -> Void) { self.rows = rows self.columns = columns self.data = Array(unsafeUninitializedCapacity: rows * columns) { buffer, initializedCount in source(&buffer) initializedCount = rows * columns } } subscript(row: Int, column: Int) -> T { get { return self.data[(row * self.columns) + column] } set { self.data[(row * self.columns) + column] = newValue } } } Multiplication is implemented by the functions shown below. import Accelerate infix operator .* func .* (lhs: Matr
3
0
923
Jun ’24
Reply to About NavigationLink Inside NavigationSplitView's Sidebar
Hi @kittens , You're seeing this behavior because the NavigationSplitView is collapsing down to a stack and showing content based on the content of the split view's columns. Here, it's showing the sidebar, and then navigating to the detail view, so the back button is taking you back to the sidebar no matter what. To change this to the behavior you are looking for, you can put a NavigationStack in the detail view. For example: NavigationSplitView { Text(Here is the FirstView) NavigationLink(Go to SecondView) { SecondView() } } detail: { NavigationStack { Text(nothing selected yet) } } Hope this helps, Sydney
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’24