Post

Replies

Boosts

Views

Activity

Remove gap between lazyvgrids in vstack
Hello, I have the code below which creates a view. Unfortunately it puts a small gap between the two LazyVGrids that I would like to eliminate. Any suggestions would be appreciated. Below is my code. Chris import SwiftUI struct SecondView: View {          var columns = [         GridItem(.fixed(100), spacing: 0.1),         GridItem(.fixed(100), spacing: 0.1),         GridItem(.fixed(100), spacing: 0.1),         GridItem(.fixed(100), spacing: 0.1),         GridItem(.fixed(100), spacing: 0.1)     ]     let principalData: convertCSVtoArray          var body: some View {         let numArrays = principalData.cvsData.count         let numElementsPerArray = principalData.cvsData[0].count                      VStack{             Text("")             Text("Historical Data")                 .font(.title)                 .padding(5)             Divider()             LazyVGrid(                 columns: columns,                 alignment: .center,                 spacing: 0)             {                 ForEach(0..<1) {row in                     ForEach(0..<numElementsPerArray) {col in                         Rectangle()                             .foregroundColor(.white)                             .overlay (Text(principalData.cvsData[row][col]).bold())                             .frame(height: 30)                             .border(Color.gray, width: 2)                     }                 }             }             ScrollView{                 LazyVGrid(                     columns: columns,                     alignment: .center,                     spacing: 0)                     {                         ForEach(1..<numArrays) {row in                             ForEach(0..<numElementsPerArray) {col in                                 Rectangle()                                     .foregroundColor(.white)                                     .overlay (Text(principalData.cvsData[row][col]))                                     .frame(height: 30)                                     .border(Color.gray, width: 0.5)                             }                         }                     }                 ForEach(0..<30){index in                     Text("")                 }             }// end scrollview         }     } }
3
0
2.7k
Sep ’21
How can I set the position of an app window on the screen for macOS with Swiftui?
I am trying to determine how to set the initial position of an app window for macOS. I have tried using NSViewRepresentable and .setFrameTopLeftPoint with no success. Is my syntax incorrect to achieve the desired results or should I be looking at some other method? struct WindowAccessor: NSViewRepresentable { @Binding var window: NSWindow? func makeNSView(context: Context) -> NSView { let view = NSView() view.window?.setFrameTopLeftPoint(CGPoint(x: 600, y: 400)) DispatchQueue.main.async { self.window = view.window } return view } func updateNSView(_ nsView: NSView, context: Context) {} } and var body: some Scene { WindowGroup { ContentView() .background(WindowAccessor(window: $window)) }
0
0
664
Nov ’21
How do I configure the headings in a SwiftUI table.
Hello, The following code displays the correct data but I am unable to figure out how to format the tables headings , including font size and alignment. Any help in pointing me in the right direction will be appreciated. Chris struct SummaryTable: View { private var localArray: [TradingDayPrices] init(passedInArray: [TradingDayPrices]) { self.localArray = passedInArray } var body: some View { let funds: [Fund] = GetSummaryTable(localArray: localArray) Table(funds) { TableColumn("Index Fund") { value in Text(value.name) .padding(.vertical, 2) } .width(90) TableColumn("Shares") { value in HStack { Spacer() Text(value.shares) Spacer() } } .width(90) TableColumn("Share Price") { value in HStack { Spacer() Text(value.sharePrice) Spacer() } } .width(90) TableColumn("Total") { value in HStack { Spacer() Text(value.total) } } .width(110) TableColumn("One Year Gain") { value in HStack { Spacer() Text(value.percentChange) Spacer() } } .width(90) } // end table .tableStyle(.inset(alternatesRowBackgrounds: true)) .padding([.leading, .trailing], 185) .padding([.top], 30) .padding([.bottom], 700) } }
0
0
736
Jan ’23
Swift Core Data - Change Location of Persistent Store
I have a program that reads in CVS data and writes it to a core data persistent store. I would like to change the location of the persistent store. Per Apple docs it appears that I should be able to achieve this by overriding it in a sub class of NSPersistentContainer. Unfortunately I have been unable to figure how to do this. Below is my attempt. The Xcode error I get is "cannot call value of non-function type URL". final class CoreDataContainer: NSPersistentContainer { let storePathURL: URL = URL(string: "file:///Users/Chris/Developer/Persistent Store")! override class func defaultDirectoryURL() -> URL { return super.defaultDirectoryURL() .absoluteURL(storePathURL) } }
1
0
1.1k
Apr ’23
Swift - SQLite3 Wal Checkpoint -> Unsafe Pointer Parameter
I have a program that adds data from CSV files to core data. Once I have saved the managed object context to the persistent store I want to run a checkpoint to flush the contents of the WAL file into the SQLite file. I have added code to my class in an attempt to do so but am unable to determine on the line "sqlite3_wal_checkpoint( ...)" what to put in the unsafe pointer parameter (denoted with ??????? in the code). class UpdateCoreData: ObservableObject { @Published var isLoading: Bool = true var moc: NSManagedObjectContext init(moc: NSManagedObjectContext) { self.moc = moc Task { await IsDataStoreEmpty(moc: self.moc) let fund1 = CSVtoCoreData(fundName: "Fund1", fileName: "Fund1.csv") let fund2 = CSVtoCoreData(fundName: "Fund2", fileName: "Fund2.csv") let fund3 = CSVtoCoreData(fundName: "Fund3", fileName: "Fund3.csv") await fund1.CSVtoCoreDataG(moc: self.moc) await fund2.CSVtoCoreDataG(moc: self.moc) await fund3.CSVtoCoreDataG(moc: self.moc) do { try moc.save() } catch { print("Error saving. \(error)") } --- start of added code let fileURL = URL(fileURLWithPath: "/Users/Chris/Downloads/Persistent Store 2/Funds.sqlite") var dataBase: OpaquePointer? sqlite3_open(fileURL.path, &dataBase ) if sqlite3_open(fileURL.path, &dataBase) != SQLITE_OK { print("Unable to open sqlite file") } else { print("Succesfully opened sqlite file") } sqlite3_wal_checkpoint(dataBase, ??????? ) sqlite3_close(dataBase) --- end of added code DispatchQueue.main.async { self.isLoading = false } } } // end init }
0
0
577
May ’23