The issue I am encountering is, I need to be able to create a view in SwiftUI that looks like a sentence of text but has blanks where the user can enter their own text. I also need a way to be able to capture the entered text from the binding, but not sure how to do multiple bindings in a loop. Ive tried a few options and the closest I have got is using LazyGrid, but it doesn't look like a normal sentence due to spacing? Any help appreciated. struct MultiText: View { @State var text = There was once a {-} that only had {-} in it. How did they get in? {-} @State var answerText: String = XXXXXXX let rows = [ GridItem(.adaptive(minimum: 80)) ] var body: some View { GeometryReader { geo in HStack { LazyVGrid(columns: rows, alignment: .leading, spacing: 0) { ForEach(text.components(separatedBy: ), id: .self) { component in if component == {-} { TextField(, text: $answerText ) } else { Text(component) } } }.frame(width: geo.size.width * 0.80) Image(systemName: flag).frame(width: 30, height: 30) }.frame(wi
Search results for
column
2,071 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
It is my understanding that the SELECT statement returns a 0 if the table does not exist and 1 if it does. Actually that statement will return a result row if the table exists, and no result rows if it doesn’t exist. If you really want a result row containing a number every time, then you could use: SELECT COUNT(*) FROM sqlite_master WHERE type = 'table' AND name = 'Contact' But this would require you to fetch the column value to check the number. Your original query actually makes this task easier by letting you simply check if a row was returned or not. the API step statement returns 101 (SQLITE_Done) if the table does not exist. That means sqlite3_step has finished stepping through all the result rows, of which there are none. But if the table does exist it does not return 101. That would be SQLITE_ROW which means it got a result row. If you were to call sqlite3_step once again (or in a loop) you would get SQLITE_DONE the next time.
Topic:
Programming Languages
SubTopic:
Swift
Tags:
Hello, I am turning to this forum because I suspect I am doing it wrong when it comes to implementing VoiceOver accessibility in my collection view. I suspect this because the system has resisted everything I have tried to do, fought it tooth and nail, and I can't see any way to get this to work. The Collection View I have a collection view that displays a large dataset. It uses a custom collection view layout to create a spreadsheet-like view. It has hundreds of rows, and each row can have hundreds of items. The items in each row do not conform to specific column widths. Their width is defined by the data they display, and for the purposes of this discussion, can be considered to be arbitrary. To the left of the table is a column of sticky headers whose position remains fixed in relation to the content. On top of the table is a row of headers, whose position also remains fixed. The Problem The default accessibility behavior that Apple has baked into UICollectionView is completely impractica
Hello everyone. I'm having a problem using the table sort function in Swiftui. Here's an example to illustrate (data is provided by an API that returns fake data) : struct CompanyListResponse: Codable { let status: String let code: Int let total: Int let data: [CompanyData] } struct CompanyData: Codable, Identifiable { let id: Int let name: String let email: String } @Observable final class ViewModel { var companies : [CompanyData] = [] func fetch() async { guard let url = URL(string: https://fakerapi.it/api/v1/companies?_quantity=200) else { return } do { let (data, _) = try await URLSession.shared.data(from: url) let decoder = JSONDecoder() let response = try decoder.decode(CompanyListResponse.self, from: data) self.companies = response.data } catch { print(Error fetching data: (error)) } } } struct ContentView: View { @State private var viewModel = ViewModel() @State private var sortOrder : [KeyPathComparator] = [.init(.name, order: SortOrder.forward)] var body: some View { Table(of: CompanyData.self, sort
Just want to clarify, suppose I want to parse a table with multiple columns each separated by “|”, I can do one of the followings and use firstMatch(of: regex) or wholeMatch(of: regex), but they assume fixed number of columns in the table. How do I deal with dynamic number of columns? // using multi-line literal let regex = #/ (|) (? (.*?)(?=|)) (|) (? (.*?)(?=|)) (|) (? (.*?)(?=|)) /# // using RegexBuilder let separator = /|/ let regexBuilder = Regex { separator Capture ( OneOrMore(.any, .reluctant) ) separator Capture ( OneOrMore(.any, .reluctant) ) separator Capture ( OneOrMore(.any, .reluctant) ) separator }
Topic:
App & System Services
SubTopic:
General
Tags:
Is there a way to print a simple report of the tests? We want a list of tests, with a report of ‘pass’ or ‘fail’ for each one. We need this for the V&V process for our app. We found what we want in the ‘Report Navigator’ (the option on the far right in the left hand column on Xcode) by clicking on ‘Test’. However, this isn’t printable. Below ‘Test’ is ‘Build’, ‘Coverage’, and ‘Log’, which can be exported, but all of them show more information that we wanted. (Photo for reference) Is there a way to print out that page when you click on ‘Test’? What am I missing here?
I'm creating a horizontal scroll view through the collection view. I used flowlayout for layout, and I set the scroll direction to horizontal. I found a bug in this situation. If the width of the item is different, line spacing is not applied, but item spacing is applied. Since it is a horizontal scroll, line spacing should be applied in the direction of the column, but item spacing is applied. Does anyone know anything about this? // // ViewController.swift // minimumLineSpacingTest // // Created by Hoonki chae on 2023/07/12. // import UIKit class TestCell: UICollectionViewCell { } class ViewController: UIViewController { let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()) override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = .white self.collectionView.frame = .init(origin: .init(x: 0, y: 100), size: .init(width: self.view.frame.width, height: 50)) self.view.addSubview(self.collectionView) self.collectionView.backgroundColor
for anyone who might have the same question/problem. here's the sample that works as I wanted. import SwiftUI struct ContentView: View { let numberOfRows = 5 let numberOfColumns = 5 @State var matrix: [[Int]] = Array(repeating: Array(repeating: 0, count: 5), count: 5) @State var selectedRow1 = 0 @State var selectedColumn1 = 0 @State var selectedRow2 = 0 @State var selectedColumn2 = 0 @State var selectedRow3 = 0 var body: some View { VStack { Image(systemName: globe) .imageScale(.large) .foregroundColor(.accentColor) Text(Hello, world!) Form { Section(header: Text(Question 1)) { Picker(Select a row:, selection: $selectedRow1) { ForEach(1...numberOfRows, id: .self) { row in Text((row)) } } .pickerStyle(SegmentedPickerStyle()) Picker(Select a column:, selection: $selectedColumn1) { ForEach(1...numberOfColumns, id: .self) { column in Text((column)) } } .pickerStyle(SegmentedPickerStyle()) } Section(header: Text(Question 2)) { Picker(Select a row:, selection: $selectedRow2) { ForEach(1..
Topic:
Programming Languages
SubTopic:
Swift
Tags:
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!
https://drive.google.com/file/d/1GWV9MYs_X4HG0XT4_-wDPPHdWOFwsRJs/view?usp=sharing Hi, everyone! So, I am trying to create an app that is like a survey app. I am new to coding by the way (less than a month) I have this long-ass code that I am trying to work. Well, it is working except for one more part of the code. I've been trying to make it work for days now and I cannot seem to figure it out. I uploaded it in a google drive link above. This is what it is: If you try to run this code in Xcode, you can see a thing like this: The app works like this, users select the pickers beside the Criteria and Relative Risk. The scores will show as: Score: 2,4 (just a sample score) criteria = row relative risk = column what I want to happen is that this score will immediately translate as a coordinate in the risk matrix below. There are 21 sets of pickers for this part of the app. The coordinates can have more than 1 value. so if there are 3 scores that have the same coordinate, such coordinate in the matrix sho
I've been trying to build an app using NavigationSplitView and SwiftUI on iOS 16. I noticed that as soon almost as the app enters the background (sometimes I have to wait a few seconds before immediately reopening the app) the contents of the NavigationSplitView are reset. This behavior differs from a NavigationStack using essentially the same path and app structure. I'm wondering if anyone has any idea why this happens? I did a little investigation and can say I've noticed a few things If using a List with a selection item specified, the selection item is set to nil when the app enters the background. For NavigationSplitView this typically will reset the downstream Detail or Content view since the value is lost If using a List without the selection parameter specified this effect is mitigated but the view still is reset and things like scroll position are wiped despite no content changing. Self._printChanges() indicates the view is unchanged despite being reset to its initial state. Using Apple's own WWDC sa
I am trying to render a list of entities that are split into sections (think CoreData NSFetchedResultsSectionInfo). This my solution, however it renders poorly. The ScrollView is far too long, scrolling is not fluid and may freeze. struct SectionsGridView: View { let results: Sections let columns = [ GridItem(.adaptive(minimum: .cellSize)) ] var body: some View { ScrollView { LazyVGrid(columns: columns, spacing: .gridSpacing, pinnedViews: .sectionHeaders) { ForEach(results) { section in Section(header: Text(section.title?.uppercased() ?? error)) { ForEach(section) { item in GridCell().environmentObject(item) } } } } } } } private extension CGFloat { static let gridSpacing = 8.0 static let cellSize = 100.0 } I believe this solution (or very similar) used to be in the documentation. I have tried several ways of doing this, either I get the scrolling issue or pinnedViews won't pin.
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 having a very weird issue using LazyVGrid that I've been banging my head over now for weeks. I have a loop that runs over a filtered list of locations and prints out the image with the location name below which is drawn from CategoryItem. let columns = [GridItem(.adaptive(minimum: 150), alignment: .top)] ScrollView { LazyVGrid(columns: columns, spacing: 10) { ForEach(categoryFilter) { landmark in let _ = print(catFilter= (landmark)) NavigationLink { DetailView(landmark: landmark) } label: { CategoryItem(landmark: landmark) } .frame(height: 185) } } } I kept getting a blank screen and could see no way around it so I put a print inside the loop and noticed that it was just continually printing the content from categoryFilter in an endless loop. If I commented out just the LazyVGrid loop (leaving just the bare ForEach loop) it works. And if I comment out just the remote fetching of the image which in my case is KFImage(URL(string: imageURLString)) (which is inside CategoryItem) the