Hi there! can someone help me with this one: func resetMatrix() { matrix = Array(repeating: Array(repeating: 0, count: numberOfColumns), count: numberOfRows) let coordinates = [ (selectedRow1, selectedColumn1), (selectedRow2, selectedColumn2), (selectedRow3, selectedColumn3) ] for (row, column) in coordinates { matrix[row - 1][column - 1] += 1 } } i can't seem to make it work. i want it to work like this: If the chosen coordinate in Question 1 is (2,2), it will place the value 1 in the matrix coordinate (2,2). If the chosen coordinate in Question 2 is also (2,2), it will increment the value in the matrix coordinate (2,2) by 1, making it 2. Similarly, if the chosen coordinate in Question 3 is (2,2), it will increment the value in the matrix coordinate (2,2) by 1 again, making it 3. Thank you!
Search results for
column
2,046 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
When showing an Alert from within a Popover that has a fixed height, the newly presented Alert is in the same position but gets limited by the Popovers height causing the title of the Alert to be hidden. Is this intentional behavior or are Alerts not supported within Popovers and I'd have to pass it through to my main view? Code: // // DemoalertPopover.swift // ******** // // Created by Thilo on 26.06.2023. // import SwiftUI struct DemoAlertPopover: View { @Environment(.dismiss) var dismiss @State private var showDeleteConfirmation = false let dateFormatter: DateFormatter = { let formatter = DateFormatter() formatter.dateFormat = dd.MM.yyyy return formatter }() var body: some View { VStack(alignment: .leading, spacing: 0) { HStack { Text(Title).font(.extraLargeTitle).lineLimit(1) Spacer() Button(action: { dismiss() }) { Label(Close, systemImage: xmark).labelStyle(.iconOnly) } } HStack(alignment: .center) { Text(Content).font(.largeTitle) Text(Content2).foregroundStyle(.secondary) } LazyVGrid(columns:
import SwiftUI import UIKit class MatrixViewController: UIViewController { let matrix = [ [A5, B5, C5, D5, E5], [A4, B4, C4, D4, E4], [A3, B3, C3, D3, E3], [A2, B2, C2, D2, E2], [A1, B1, C1, D1, E1], ] let matrixLabelSize: CGFloat = 30.0 override func viewDidLoad() { super.viewDidLoad() setupMatrixView() } func setupMatrixView() { let matrixView = UIView() matrixView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(matrixView) let matrixViewWidth = CGFloat(matrix[0].count) * matrixLabelSize let matrixViewHeight = CGFloat(matrix.count) * matrixLabelSize NSLayoutConstraint.activate([ matrixView.centerXAnchor.constraint(equalTo: view.centerXAnchor), matrixView.centerYAnchor.constraint(equalTo: view.centerYAnchor), matrixView.widthAnchor.constraint(equalToConstant: matrixViewWidth), matrixView.heightAnchor.constraint(equalToConstant: matrixViewHeight) ]) var positionCounts: [String: Int] = [:] //counting the number of occurences - - - - - - this part for coordinate in coordinates { let row = coor
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
From what I've understood, it doesn't need to be 5 dimensional, but rather, 2 dimensional. The dimension in a matrix doesn't correspond to the number of rows and columns. In your case, two dimensions seems enough: one for the severity (from one to five), and one for the likelihood (1 to 5). You could therefore store data like so : Matrix[2][5] = 3 (which would mean that there are 3 questions that have a severity of 2 and a likelihood of 3). A good visual representation of the dimensions of a matrix would be the following. A one-dimensional matrix is just an array/list. A two dimensional array corresponds to an Excel/Numbers spreadsheet. And a three dimensional array could be use to store the coordinates of the cubes composing a Rubik's Cube, for example. Above 3, it's hard to have a visual representation. A 5-dimensional matrix would be suitable if you had 5 different sliders per question. Therefore, if you can represent your table in a spreadsheet, it means that two dimensions is enough. Let me know
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
I'm fairly new to Swift programming so I might be overlooking something, but I'm puzzled why the following code doesn't properly insert a row in a DataFrame. The goal is to move a row at a given index to a new index. I would normally: Copy the row that I want to move Remove the row from the original dataset Insert the copy to the new position The CSV I'm using is from Wikipedia: Year,Make,Model,Description,Price 1997,Ford,E350,ac, abs, moon,3000.00 1999,Chevy,Venture Extended Edition,,4900.00 1999,Chevy,Venture Extended Edition, Very Large,,5000.00 1996,Jeep,Grand Cherokee,MUST SELL! air, moon roof, loaded,4799.00 My code (Swift playground): import Foundation import TabularData let fileUrl = Bundle.main.url(forResource: data, withExtension: csv) let options = CSVReadingOptions(hasHeaderRow: true, delimiter: ,) var dataFrame = try! DataFrame(contentsOfCSVFile: fileUrl!, options: options) print(Original data) print(dataFrame) let rowToMove: Int = 2 let row = dataFrame.rows[rowToMove] print(Row to move) print(ro
The code is very long so i hope this edit is sufficient to read. Where do you use relativeRiskPickerIndex31? - there are 31 questions in this part of the app,. each app has 2 sets of answers for users to choose from. #1 Slope Angle (they choose answer from picker one) and picker two in the relativeRiskPickerIndex.. basically there are from 1 until 31 risk picker indexes using this: let relativeRiskChoices = [Select, Negligible, Minor, Moderate, Significant, Major] let relativeRiskScores = [-,A, B, C, D, E] //the code above this line is from another swift file that just gets called to the file to the code below. The state var values are all zero. There is no error message inside the code lines but when I run the simulator and try to run and pick answers from the questions and answers inside the simulator, it Freezes and stops working. so i have to force quit it again to try to run it again. however, if i do not use the pickers and just directly try to export pdf, it works. The last time I tried this popped up
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
FB9108925 FB10408005 Since Apple Silicon we've seen a lot of WebDAV instability in macOS 11.x, 12.x and now 13.x that isn't found on x86 Macs. Some were fixed in earlier minor OS upgrades (e.g. webdavfs-387.100.1 that added a missing mutex init), but it's still highly unreliable. The purpose of this post is to put more focus on the bug, see if there is something else we can do to help solve this, as well as hear about potential workarounds from other people experiencing the same problems. I've got a reproducible case described below that triggers a deadlock in VFS every time, requiring a hard reboot to fully recover. Before reboot I've captured this stack trace showing the WebDAV/VFS/UBC/VM layers getting tangled up (macOS 13.2 Build 22D49 running on Macmini9,1): Thread 0x16358 1001 samples (1-1001) priority 46 (base 31) 1001 thread_start + 8 (libsystem_pthread.dylib + 7724) [0x18d2e0e2c] 1001 _pthread_start + 148 (libsystem_pthread.dylib + 28780) [0x18d2e606c] 1001 ??? (diskarbitrationd + 99400) [0x100d5c448
So basically I can tell that the images are being saved by the system (it shows it on the debug terminal) however whenever I close, and then reopen the app the images firstly aren't there at all but also whenever I search the address name I saved them as... I have tried diagonsing the problem by changing UUID's, changing PNGs to JPGS - no matter what I do it does not show once the application has closed. I think it might have to do with how the image are .HEIF (apple's standard) but I don't have any concrete evidence to back this up. If anyone can help it would be greatly apperciated. import SwiftUI import MapKit import CoreLocation struct ContentView: View { @StateObject private var mapAPI = MapAPI() @State private var text = @State private var locationInfo: String = @State private var showLocationInfo = false @State private var imageUrls = [String]() // Array to store image URLs @State private var showImagePicker = false @State private var showCamera = false @State private var selectedImage: UIImage? @Sta
I have a view that shows a table and 4 buttons. Each button allows the user to step forward and backwards through the data. Buttons are enabled and disabled based on where you are in the data. If you are less than 200 values to the end of the data for example, the Page Down - 200 button is disabled. Everything works fine if the mouse is used to run the code associated with each button. But in this case I think the buttons never get focus. Focus I think remains with the sidebar content item that brought up the table view (am using a navigation split view). If I tab over to the page down 200 button and use the space bar to run its associated code I get the error AttributeGraph: cycle detected through attribute 864480. I think the problem lies with attempting to disable the button while it has focus but am not 100% sure. I have tried to change the focus prior to disabling the button but I get the same error. I think there is some fundamental that I am missing. Below is my table view along with the page down 200
Hi ! I am having a very strange problem. I display a list of elements, and I created a view that takes this element as a parameter in order to allow the user to modify it in another view. my var with a forEach : @Binding var liste : Liste my code : ScrollView { LazyVGrid(columns: [GridItem(.adaptive(minimum: 100))], spacing: 5) { ForEach(liste.cartes) { c in NavigationLink(destination: ModifierUneCarte(carte: c)) { VStack { Text(c.devant) .font(.system(size: 14)) Divider() Text(c.derriere) .font(.system(size: 14)) } } } } } and my ModifierUneCarte : struct ModifierUneCarte: View { [...] @Binding var carte: Carte [...] And I have this error on a lot of lines : Conflicting arguments to generic parameter 'Content' ('<>' vs. '<>' vs. '<>' vs. '<>') but it's because of : NavigationLink(destination: EditMap(map: c)) { because when I remove it everything works...
I submitted FB12211784 the end of May. It contains a do-nothing-much app that creates a two column table of 10K entries. Selecting an item in the table causes the color of the text in the first column to change. On my 2019 intel iMac there is about a 140 msec delay between selection and the color change. That is noticeable. I just re-ran the code using a brand new Mac Studio with M2 Max. It still takes over 100 msec. Still noticeable.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
// Page 1: Map Search VStack { ZStack(alignment: .topLeading) { Map(coordinateRegion: $mapAPI.region, annotationItems: mapAPI.locations) { location in MapMarker(coordinate: location.coordinate, tint: .red) } .ignoresSafeArea() VStack { HStack { TextField(Enter an address, text: $text) .textFieldStyle(.roundedBorder) .padding(.horizontal) .foregroundColor(.black) Button(action: { fetchLocationInfoFromWikipedia(for: text) mapAPI.getLocation(address: text, delta: 0.5) showLocationInfo = true }) { Image(systemName: magnifyingglass) .foregroundColor(.black) } .padding(.leading, -50) } .padding() if showLocationInfo { VStack { Spacer() Rectangle() .fill(Color.white) .frame(height: 250) .frame(width: 400) .cornerRadius(15) .overlay( ScrollView { Text(locationInfo) .foregroundColor(.black) .padding(.horizontal, 10) .font(.system(size: 14)) .font(.custom(Serif, fixedSize: 14)) } .padding() ) .padding(.horizontal, 20) .padding(.bottom, 10) // Adjust the bottom padding here HStack(spacing: 70) { Button(action: { // Open
I moved the on appear to the h stack but the table rows portion of the table still ran before the on appear resulting in an index out of range error. So I added the suggested state variable and if statement. The view now works perfectly. Thank you again for providing great advice. Below is the updated code. struct DataTable: View { @ObservedObject var vm: ButtonsViewModel = ButtonsViewModel.shared var closingValues: [TradingDayClose] var heading: String = @State private var hasAppeared = false init(fundName: String, closingValues: [TradingDayClose]) { self.heading = fundName self.closingValues = closingValues } var body: some View { HStack { Spacer() .frame(width: 150) GroupBox(heading) { if hasAppeared { Table (of: TradingDayClose.self) { TableColumn() { closingValue in Text(dateToStringFormatter.string(from: closingValue.timeStamp!)) .id(closingValue.timeStamp!) .textFormatting(fontSize: 14) .frame(width: 100, alignment: .center) } // end table column TableColumn() { closingValue in Text(String(fo
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
I have a view that displays core data values (passed in as closingValues) in a data table. To make the view generic, so I can pass in arrays of different lengths (all are from the same entity and thus attributes) and account for the view having already been called with a different set of values, I need to initialize the showData array contained in the associated view model. I attempt to do so in the init of the view but I get an error message publishing changes from within a view updates is not allowed. This will cause undefined behavior. It should be noted that in the view model showData is Published and initialized = []. I attempted to do the initialization in the views onappear but the tables rows: ForEach runs before onappear and I get an index out of range on the first call to the view. I tried adding @MainActor to the view models class, which also failed to solve the problem. I am clearly not understanding a concept. Below is the code for the view. struct DataTable: View { @ObservedObject var vm: Button
Thank you for responding to my question. Below is a simplified code example that displays two SF Symbol images on a Grid View, as seen in the gif. I've included a basic DragGesture but I have a feeling it isn't the right approach. In order for it to work the onEnded closure would need to somehow map the offset coordinate into a Square enum case so that I could update the ModelState. I intend for the board and pieces to scale to fit the available space so the size of the squares won't be known beforehand, making the coordinate mapping difficult. Maybe **GeometryReader ** could solve that but I could see the code becoming a mess. I see other drag and drop methods in the documentation, surely one them is designed to better fit this use case. dropDestination seems like a suitable candidate but I think read somewhere that it doesn't work with SF Symbols. I'm looking for guidance from someone familiar with Apple's documentation because they provide little explanations themselves (I've watched WWDC videos). Also the
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: