Post

Replies

Boosts

Views

Activity

SwiftData Tables disappearing while test my app!
I begin testing my IOS swiftdats Xcode 15 swift 5 on Sonoma and I am able to create my siwftdata tables as well as add records to several of the tables, Then as I proceeded with my te tables disappear and I get this error in the Xcode debug console: error: Error: Persistent History (6) has to be truncated due to the following entities being removed: ( AppSettings, Invoice, Clientele, Pay, InvoiceItem, TrackingArt ) This app used to work fine and as I was making changes it started behaving in this manner. Beside the code I will supply the entire debug console with the attached file debugConsole.txt Here is how I have the swift data containers setup. import SwiftData import TipKit import CloudKit @main struct ArtManagerApp: App { @StateObject private var copyInvoiceDetails = CopyInvoiceDetails() @StateObject private var copyPaymentDetails = CopyPaymentDetails() @StateObject private var artTypeSettings = ArtTypeSettings() @StateObject private var tipManager = TipManager() // @Query(sort: \ArtPiece.artPieceID, order: .forward) private var artPieces: [ArtPiece] // @Query(sort: \AppSettings.setID, order: .reverse) private var settingsList: [AppSettings] var sharedModelContainer: ModelContainer = { let schema = Schema([ ArtPiece.self, Clientele.self, TrackingArt.self, Invoice.self, InvoiceItem.self, AppSettings.self, Pay.self ]) let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false) do { return try ModelContainer(for: schema, configurations: [modelConfiguration]) } catch { fatalError("Could not create ModelContainer: \(error)") } }() var body: some Scene { WindowGroup { ContentView() .navigationTitle("🎨 Art Manager") .environmentObject(artTypeSettings) .environmentObject(copyInvoiceDetails) .environmentObject(copyPaymentDetails) .environmentObject(tipManager) // Pass it to the ContentView .modelContainer(sharedModelContainer) } } } class TipManager: ObservableObject { @Published var tips: [ArtManagerTip] = [] init() { loadTips() } func loadTips() { tips = [ArtManagerTips.search_tip, ArtManagerTips.delete_tip, ArtManagerTips.extendedSearch_tip, ArtManagerTips.searchPayments_tip, ArtManagerTips.searchArt_tip, ArtManagerTips.librarySearch_tip, ArtManagerTips.artMaintenanceSearch_tip] } } class CopyPaymentDetails: ObservableObject { @Published var payNumber: Int32 = 0 @Published var payType: String = "" @Published var payPatronID: Int32 = 0 @Published var payPatronName: String = "" @Published var payPatronAddress: String = "" @Published var payPaymentAmount: Double = 0.0 @Published var payDatePayed: Date = Date() } class CopyInvoiceDetails: ObservableObject { @Published var invoiceNumber: Int32 = 0 @Published var invoicePatronName: String = "" @Published var invoicePatronPO: String = "" @Published var invoiceDateCreated: Date = Date() @Published var artPieceIDSaved: [Int32] = [] }
7
0
1.3k
Aug ’24
How to use combo box cell in a tableView
I have a test app with a tableView that has a comboBoxCell for one of the columns in Xcode 12: The view controller code is as follows: // //  ViewController.swift //  ComboBoxExample // //  Copyright © 2016 yourCompany. All rights reserved. // import Cocoa class ViewController: NSViewController, NSComboBoxCellDataSource {     var states = ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware",                   "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky",                   "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi",                   "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico",                   "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania",                   "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont",                   "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"]     @IBOutlet weak var itemComboCell: NSComboBoxCell!     override func viewDidLoad() {         super.viewDidLoad()         itemComboCell.usesDataSource = true         itemComboCell.dataSource = self         self.itemComboCell.completes = true         // Do any additional setup after loading the view.     }     override var representedObject: Any? {         didSet {         // Update the view, if already loaded.         }     }     func numberOfItemsInComboBoxCell(in comboBoxCell: NSComboBoxCell) - Int {       // anArray is an Array variable containing the objects         return states.count     }     func comboBoxCell(_ comboBoxCell: NSComboBoxCell, objectValueForItemAt index: Int) - Any {         return (states[index])     } } When running the example I get the following error: 2021-03-05 15:16:29.940373-0600 ComboBoxExample[40515:1914724] *** Illegal NSComboBoxCell data source (ComboBoxExample.ViewController: 0x600000e501b0).  Must implement numberOfItemsInComboBoxCell: and comboBoxCell:objectValueForItemAtIndex: How do I resolve this?
6
0
1.4k
Mar ’21
How to use NSSpellChecker and NSTextCheckingController?
I have been looking for information on how to implement NSSpellChecker and NSTextCheckingController the last couple of days and have come up empty. Does anybody of some information using these two AppKit API's or even better an example on using them with an IBOutlet text field? I understand Apple use to make available the source code for textEdit app? Does anybody know if this is still the case? Thanks
5
0
1.3k
Feb ’21
NSPrintInfo design report
I am developing an macOS Xcode 12 app that requires printing. I have a basic understanding how to implement printing, I understand that I need to create a subclass of NSview to get going. However, I was wondering how to go about designing the report? Is this done with interface builder like designing a window layout or is all done with code, ie supplying position (x,y), headings, font, graphics, font size.. etc. How is this done? Also, does anybody have any tutorials on this? I have one example but it is very minimal print out, basically it prints a tableview with two columns. I got this from Coca Programming chapter 27, Big Nerd Ranch.
5
0
976
May ’21
How to call function in NSViewController?
class CustViewController: NSViewController { @IBOutlet weak var tableView: NSTableView! @IBOutlet weak var statusLabel: NSTextField! fileprivate var selectedOptionFromMenu = "" @objc var contacts:[Person] = [] @objc var backUpContacts:[Person] = [] @IBAction func printCustomers(_ sender: Any?) { I would like to call the printCustomers function in the CustViewController from another class (NSWindowController). How is this coded in the NSWindowController class? I tried the following: let printAction = CustViewController.printCustomers(<#T##self: CustViewController##CustViewController#> ) but don't know how to code argument in this and this may be not be the way to do this?
Topic: UI Frameworks SubTopic: AppKit Tags:
5
0
703
Aug ’22
Why does the first image behave differently ?
I have the following test code: import SwiftUI struct ContentView: View { @State private var draggedImages: [UIImage?] = Array(repeating: nil, count: 5) @State private var savedToDisk = false var body: some View { VStack { HStack { ForEach(0..<5, id: \.self) { index in let image = draggedImages[index] ?? UIImage(systemName: "photo") Image(uiImage: image!) .resizable() .frame(width: 80, height: 80) .padding() .background(Color.blue) .foregroundColor(.white) .cornerRadius(10) .onDrag { return NSItemProvider(object: UIImage(systemName: "photo")!) } .onDrop(of: ["public.image"], isTargeted: nil) { providers, _ in providers.first?.loadDataRepresentation(forTypeIdentifier: "public.image") { data, error in if let data = data, let uiImage = UIImage(data: data) { draggedImages[index] = uiImage saveImageToDisk(image: uiImage, imageNumber: index) } } return true } } .alert(isPresented: $savedToDisk) { Alert(title: Text("Images Saved"), message: Text("The images have been saved to disk."), dismissButton: .default(Text("OK"))) } Spacer() } } .padding() } private func saveImageToDisk(image: UIImage, imageNumber: Int) { if let imageData = image.pngData() { do { let documentsDirectory = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) let imageUrl = documentsDirectory.appendingPathComponent("image_\(imageNumber).png") try imageData.write(to: imageUrl) savedToDisk = true } catch { print("Error saving image: \(error)") } } } } I can drag and drop as well as the dragged image is save on the second placeholder thru the fifth but not the first When I drag and drop to the first image another files app opens but when I close this the image is not saved. Any Ideas why the first image behaves differently to all the others? I test on Sonoma and Xcode 15 beta 7, I wil give it a try on Ventura and Xcode 14 later today to see if the same thing happens. Thanks
5
0
972
Sep ’23
Xcode 13.2 and Github - No Packages listed
I connected Github to Xcode 13.2 (Monterey macOS) successfully, however I do not see any packages available when I select Github as the source. I did download Xcode 13.2 from the developers website and it did fix some problems I was having with Xcode from the App Store but did make any difference to the issue above. Anybody else have this issue with Xcode 13.2?
4
0
1.2k
Mar ’22
NSPredicate format for date comparison
I have the following code to search a tableView. The contains format works fine for string arguments however can't seem to find the correct format to work with date arguments.   @objc func invoiceSearch(sender:NSSearchField) {     //    print ("\(#function): \(sender.stringValue)")             let searchString = sender.stringValue             var predicate:NSPredicate = NSPredicate()             if searchString.isEmpty {                 invoices = self.backUpInvoices             }             else{       // search field contains data                 if (invoiceSearchField.cell as? NSSearchFieldCell)?.placeholderString == "All" {                     predicate = NSPredicate(format: "invoiceNumber contains %@ OR invoiceCustName contains %@ OR invoiceStatus contains %@ OR invoiceDateCreated >= %@",searchString,searchString,searchString,searchString)                 }                 else if (invoiceSearchField.cell as? NSSearchFieldCell)?.placeholderString == "invoice Number" {                     predicate = NSPredicate(format: "invoiceNumber contains %@",searchString)                 }                 else if (invoiceSearchField.cell as? NSSearchFieldCell)?.placeholderString == "invoice Customer"{                     predicate = NSPredicate(format: "invoiceCustName contains %@",searchString)                 }                 else if (invoiceSearchField.cell as? NSSearchFieldCell)?.placeholderString == "invoice Status"{                     predicate = NSPredicate(format: "invoiceStatus contains %@",searchString)                 }                 else if (invoiceSearchField.cell as? NSSearchFieldCell)?.placeholderString == "Invoice Date"{                       predicate = NSPredicate(format: "invoiceDateCreated >= %@", searchString as CVarArg)                 }                 invoices = (self.backUpInvoices as NSArray).filtered(using: predicate) as! [Invoice]             }             invoiceCount = "Found \(items.count ) Invoices"             invoiceStatusLabel.stringValue = invoiceCount             self.tableView.reloadData()     } InvoiceDateCreated is defined by the following within a NSObject class: @objc   var invoiceDateCreated: Date? = Date() The error I get when trying to search on date is 2022-09-26 09:14:36.638553-0500 CashToMe[9107:6838576] [General] -[NSTaggedPointerString objCType]: unrecognized selector sent to instance I have read through the following documentation Apple Doc for NSPredicate How can I fix this. Also, if there is a better/newer way to code this I am open to changing the code. Thanks
4
0
2.0k
Sep ’22
How to add an IBAction to a macOS tableView Cell
I have a macOS tableview I have a textfield as a column along with an IBAction code to capture the data from this field. I wanted to add continuous spell check for this column . So, I decided to change the column from a TextField to a ScrollView to take advantage of the continuous spell check. Using Xcode 14 I changed the Cell to a custom Cell. The custom cell has a scrollview object as the object because I want to take advantage of the built in continuous spell checking instead of using a textfield. All is well with this implementation until I tried to add a IBAction code for when I enter text in the scrollview/textView field. There does not seem to be a way to capture the text? Am I trying to do something that can't be done or is there a way to add continuous spell check to a textField?
4
0
1.4k
Nov ’22
macOS Xcode 14.2 app applicationwillterminate function is not called
I want to put some code to be run when my app terminates but the following:        func applicationWillTerminate(_ aNotification: Notification) {             // Insert code here to tear down your application             print("Termination Code")         } in the AppDelegate class is not called, any ideas how to fix this issue. I saw this posts https://developer.apple.com/forums/thread/126418 but I do not have an info.plist. I think the info.plist is not longer needed. The following doc does not have much to say about this?? https://developer.apple.com/documentation/appkit/nsapplicationdelegate/1428522-applicationwillterminate
4
0
1.4k
Jan ’23
Populate one column based on values of other column in a NSTableView
How do you populate one column based on values of other column for a macOS app using Xcode 12 in a tableView? The value of the first column comes from a comboBox which I get control by using the following code connected to the comboBox: @IBAction func comboAction(_ sender: NSComboBox) {         print("Combo selected", sender.selectedTag(), sender.stringValue, sender.indexOfSelectedItem, sender.identifier as Any)         } Then base on the value of the comboBox column within the comboAction function I want to populate column 2. Can this be done? If so, how
3
0
763
Mar ’21
How to Initialize a structure with in a class?
From the class below how do I initialize chartEntry for the structure array? As it is below chartEntry is outside scope of init? class ChartSeriesRow: ObservableObject {     var id = UUID()     var chartCategory: String     struct chartSeriesData{         var chartEntry: [ChartData]     }     struct ChartData: Codable, Identifiable, Hashable {         var id = UUID()         let chartMonth: String         let chartSales: String     }     init() {         chartCategory = ""         chartEntry = chartSeriesData: [ChartData.chartMonth: "01",  ChartData.chartSales: "10.0"]     }      }
3
0
861
Nov ’22
Progress Indicator not working as expected
I have a test project with a bar progress indicator create on Ventura with Xcode 14.3.1., It does not show the any animation until the @IBAction function completes. I want to show progress as it progresses not a just the end? Any ideas how to fix this? Below is my test project code.. // // ViewController.swift // ProgressTest // // Created by Bob on 6/5/23. // import Cocoa class ViewController: NSViewController { @IBOutlet weak var progressIndicator: NSProgressIndicator! // var progress: Double = 0.0 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override var representedObject: Any? { didSet { // Update the view, if already loaded. } } @IBAction func progressStart(_ sender: Any) { // Start the progress animation progressIndicator.startAnimation(self) // Do some work here... // Do some work here... var progress: Double = 0.0 for _ in 0..<100 { // Update the progress value in a loop progress += 1.0 progressIndicator.doubleValue = progress // progress = Double(i) // progressIndicator.increment(by: 10) // progressIndicator.doubleValue = progress // Do some work here... } // Stop the progress animation progressIndicator.stopAnimation(self) } } thanks Bob
3
0
1.3k
Jun ’23