Post

Replies

Boosts

Views

Activity

Drawing an NSImage using COCOA Drawing
I have the test code below which draws a box with some text in it. I would like to add an image to the drawing. The function getCompanyLogo returns an NSImage and I would like to then add this image to the drawing. I have read apple's archive doc at the Drawing with COCOA but do not see how to complete this. How is this done? Thanks import Cocoa @IBDesignable class invoiceSectionTop: NSView {     override func draw(_ dirtyRect: NSRect) {         super.draw(dirtyRect)         let context = NSGraphicsContext.current?.cgContext         let length = CGPoint(x: 200, y: 50)         let p1 = CGPoint(x: 0, y: 50)         let shape = "square"         context!.beginPath()         context!.move(to: p1)         if shape == "line" {             let pointEnd = CGPoint(x: p1.x + length.x, y: p1.y + length.y)             context!.addLine(to: pointEnd)         } else if shape == "square" {             let p2 = CGPoint(x: p1.x + length.x, y: p1.y)             let p3 = CGPoint(x: p1.x + length.x, y: p1.y + length.y)             let p4 = CGPoint(x: p1.x, y: p1.y + length.y)             context!.addLine(to: p2)             context!.addLine(to: p3)             context!.addLine(to: p4)             context!.addLine(to: p1)         }         context!.setStrokeColor(red: 1, green: 1, blue: 1, alpha: 1.0)         context!.setFillColor(red: 0, green: 1, blue: 0, alpha: 1)         context!.setLineWidth(2.0)         context!.strokePath()         let image = getCompanyLogo()      // getCompanyLogo returns a NSImage object    //     NSGraphicsContext.current?.NSIm.draw(cgimage!, in: dirtyRect)         let textColor = NSColor(calibratedRed: 1, green: 1, blue: 1, alpha: 1.0)         let textColorB = NSColor(calibratedRed: 1, green: 1, blue: 1, alpha: 0.0)         let rect = CGRect(x: 200, y: 200, width: 30, height: 130)         let paragraphStyle = NSMutableParagraphStyle()         paragraphStyle.alignment = .center         let attr = [NSAttributedString.Key.paragraphStyle: paragraphStyle, NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.backgroundColor: textColorB, NSAttributedString.Key.font:NSFont.init(name: "HelveticaNeue-Thin", size: 14)]         let q: NSString = "hello, world"         let center = CGPoint(x: 0, y: 50)         q.draw(at: center, withAttributes: attr as [NSAttributedString.Key : Any])     } }
1
0
1.2k
Aug ’22
How to sort NSTableView Date Column?
I have a date column in a macOS NSTableView column in YYYY-MM-DD format and when using the code below the sort does not sort way I want. When sorting ascending. It has the year correct but the month is in reverse order. See image below. How can I fix this?  func sortInvoices(invoiceColumn: String, ascending: Bool) {          enum SortOrder {             static let Date = "invoiceDateCreated"             static let Number = "invoicenumber"             static let Customer = "invoicecustomer"             static let Status = "invoicestatus"         }         switch invoiceColumn {         case SortOrder.Date:            invoices.sort { (p1, p2) -> Bool in                guard let id1 = p1.invoiceDateBilled, let id2 = p2.invoiceDateBilled else { return true }                if ascending {                    return id1 < id2                } else {                    return id2 < id1                }            }
1
0
921
Sep ’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
2k
Sep ’22
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
887
Nov ’22
How to populate an array within a Class Instance?
I have the following code: class ChartSeriesRow: ObservableObject {     var id = UUID()     var chartCategory: String     struct ChartSeriesData {         var chartEntry: [ChartData]     }     var chartSeries : ChartSeriesData     struct ChartData: Codable, Identifiable, Hashable {         var id = UUID()         let chartMonth: String         let chartSales: String     }     init() {         chartCategory = ""         chartSeries = ChartSeriesData(chartEntry: [ChartData(chartMonth: "01", chartSales: "10.0") ] )     } } How do I populate ChartSeriesData? I thought I could just add the following: However coding this way there is no append method. extension ChartSeriesRow {     func addRow(chartRow: ChartSeriesData){          ChartSeriesRow.ChartSeriesData.chartEntry.append(contentsOf: chartRow)     } }
2
0
855
Nov ’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
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
1k
Sep ’23
Deleting CloudKit data
I have been testing an app which uses cloudKit with SWIFTDATA and after testing for several months my 200GB iCloud store is showing 168GB for iCloud Drive. Now my iCloud drive is only 22.6GB so the rest of the 168GB must be data from my app. Also, I have function in my app to delete all iCloud Data which I thought that should clean up iCloud storage but it does not. I tried resetting the Develop Environment but no change to iCloud data. Also I have several other containers in iCloud created while getting iCloud working which I would like to delete but I understand you can’t. https://forums.developer.apple.com/forums/thread/45251?answerId=788694022#788694022 Bottom line cloudkit console has been pretty much useless for me and I need a way to manage (delete containers and data). Am I missing something?
1
0
1.1k
Jun ’24
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.4k
Aug ’24
NavlgationLink Code not working on macOS Sequoia
This code which works fine on macOS Sonoma but on Sequoia the navigationLinks do not work? VStack { Text("Application Global Values") .font(.largeTitle) .fontWeight(.bold) .padding(.bottom, 10) Text("Select each of the Descriptors, enter the values and when done then Tap on (Add/Save)") .font(.title3) .foregroundColor(.secondary) List { NavigationLink("Enter Core Descriptors", destination: CoreView(systemSettings: $systemSettings)) .padding() // Add padding to create some space inside the border // .background(Color.white) // Optional: Add a background color if needed // .border(Color.red, width: 2) // Add a red border with a specified thickness .overlay( RoundedRectangle(cornerRadius: 10) // Specify the corner radius for rounded corners .stroke(Color.red, lineWidth: 2) // Define the color and thickness of the border ) SetupDivider(thickness: 3) NavigationLink("Enter Counters Descriptors", destination: CountersView(systemSettings: $systemSettings)) .padding() // .background(Color.white) .overlay( RoundedRectangle(cornerRadius: 10) // Specify the corner radius for rounded corners .stroke(Color.red, lineWidth: 2) // Define the color and thickness of the border ) SetupDivider(thickness: 3) NavigationLink("Create Custom Descriptors", destination: UserFieldsView(userFields: $userFields)) .padding() // .background(Color.white) .overlay( RoundedRectangle(cornerRadius: 10) // Specify the corner radius for rounded corners .stroke(Color.red, lineWidth: 2) // Define the color and thickness of the border ) SetupDivider(thickness: 3) NavigationLink("View All Descriptors", destination: DefaultDetailView(userFields: $userFields, systemSettings: $systemSettings)) .padding() // .background(Color.white) .overlay( RoundedRectangle(cornerRadius: 10) // Specify the corner radius for rounded corners .stroke(Color.red, lineWidth: 2) // Define the color and thickness of the border ) SetupDivider(thickness: 3) }
1
0
434
Aug ’24
Swiftui Table statement conditional table columns
Is it possible to have conditional table columns for a swifui Table statement? Like for this code TableColumn("Image") { artPiece in if let imageData = artPiece.artImage.first, let image = UIImage(data: imageData!) { Image(uiImage: image) .resizable() .frame(width: 50, height: 50) } else { Image(systemName: "photo") .resizable() .frame(width: 50, height: 50) } } .customizationID("Image") TableColumn("Name", value: \.artName) .customizationID("Name") TableColumn ("Art ID", value: \.artPieceID) { artPiece in Text(String(artPiece.artPieceID)) } .customizationID("Art ID") have a conditional TableColumn for this part of my SWIFTDATA model var artDefinedFields: [ArtDefinedFields] = [] or if I change the variable string array to this var artDefinedFields: [ArtDefinedFields] = Array(repeating: ArtDefinedFields(), count: 10), initialize the array with "None" and only create a TableColumn when there is aArtDeginedFields value other than "None"
3
0
665
Aug ’24
How to save an Image to NsData object and then retrieve.
My environment is as follows: Xcode 12, macOS BS developing a macOS app. I have an IBOutlet from a IB window as @IBOutlet weak var imageView: NSImageView! So, I want to store imageView to a NSData object and then save the NSData object in my UserDefaults. Once I saved the Image in my UserDefaults I need to be able to decode or retrieve the image for use in other parts of the app. How is this done? Also, I have seen some cautions about converting an Image to NSData object and retrieving. It seems the retrieved image may not be 100% as it was originally. Is this true and if so why? Thanks
2
0
1.2k
Jun ’21
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
How to Activate Printer Panel
How do you activate the Printer Panel using a toolbar printer Icon in a macOS app like you get when I select File -> Print (CMD-P)? This is in a tableView view based screen. I have connected the first responder to "print:" thinking this might work but the printer Icon in the toolbar remains grayed-out. Also, tried connecting it to a @IBAction func but it still is grayed out. I am using Xcode 13 and 14 beta
0
0
388
Jul ’22
Drawing an NSImage using COCOA Drawing
I have the test code below which draws a box with some text in it. I would like to add an image to the drawing. The function getCompanyLogo returns an NSImage and I would like to then add this image to the drawing. I have read apple's archive doc at the Drawing with COCOA but do not see how to complete this. How is this done? Thanks import Cocoa @IBDesignable class invoiceSectionTop: NSView {     override func draw(_ dirtyRect: NSRect) {         super.draw(dirtyRect)         let context = NSGraphicsContext.current?.cgContext         let length = CGPoint(x: 200, y: 50)         let p1 = CGPoint(x: 0, y: 50)         let shape = "square"         context!.beginPath()         context!.move(to: p1)         if shape == "line" {             let pointEnd = CGPoint(x: p1.x + length.x, y: p1.y + length.y)             context!.addLine(to: pointEnd)         } else if shape == "square" {             let p2 = CGPoint(x: p1.x + length.x, y: p1.y)             let p3 = CGPoint(x: p1.x + length.x, y: p1.y + length.y)             let p4 = CGPoint(x: p1.x, y: p1.y + length.y)             context!.addLine(to: p2)             context!.addLine(to: p3)             context!.addLine(to: p4)             context!.addLine(to: p1)         }         context!.setStrokeColor(red: 1, green: 1, blue: 1, alpha: 1.0)         context!.setFillColor(red: 0, green: 1, blue: 0, alpha: 1)         context!.setLineWidth(2.0)         context!.strokePath()         let image = getCompanyLogo()      // getCompanyLogo returns a NSImage object    //     NSGraphicsContext.current?.NSIm.draw(cgimage!, in: dirtyRect)         let textColor = NSColor(calibratedRed: 1, green: 1, blue: 1, alpha: 1.0)         let textColorB = NSColor(calibratedRed: 1, green: 1, blue: 1, alpha: 0.0)         let rect = CGRect(x: 200, y: 200, width: 30, height: 130)         let paragraphStyle = NSMutableParagraphStyle()         paragraphStyle.alignment = .center         let attr = [NSAttributedString.Key.paragraphStyle: paragraphStyle, NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.backgroundColor: textColorB, NSAttributedString.Key.font:NSFont.init(name: "HelveticaNeue-Thin", size: 14)]         let q: NSString = "hello, world"         let center = CGPoint(x: 0, y: 50)         q.draw(at: center, withAttributes: attr as [NSAttributedString.Key : Any])     } }
Replies
1
Boosts
0
Views
1.2k
Activity
Aug ’22
How to sort NSTableView Date Column?
I have a date column in a macOS NSTableView column in YYYY-MM-DD format and when using the code below the sort does not sort way I want. When sorting ascending. It has the year correct but the month is in reverse order. See image below. How can I fix this?  func sortInvoices(invoiceColumn: String, ascending: Bool) {          enum SortOrder {             static let Date = "invoiceDateCreated"             static let Number = "invoicenumber"             static let Customer = "invoicecustomer"             static let Status = "invoicestatus"         }         switch invoiceColumn {         case SortOrder.Date:            invoices.sort { (p1, p2) -> Bool in                guard let id1 = p1.invoiceDateBilled, let id2 = p2.invoiceDateBilled else { return true }                if ascending {                    return id1 < id2                } else {                    return id2 < id1                }            }
Replies
1
Boosts
0
Views
921
Activity
Sep ’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
Replies
4
Boosts
0
Views
2k
Activity
Sep ’22
structured editing popover with Xcode 14.1 beta 3
I don't see the structured editing popover when I command right click on an IOS SwiftUI project when I create a new project with just "Hello World" like I see in Xcode 13. Am I missing some thing or is this a bug? Thanks
Replies
6
Boosts
0
Views
2.1k
Activity
Sep ’23
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"]     }      }
Replies
3
Boosts
0
Views
887
Activity
Nov ’22
How to populate an array within a Class Instance?
I have the following code: class ChartSeriesRow: ObservableObject {     var id = UUID()     var chartCategory: String     struct ChartSeriesData {         var chartEntry: [ChartData]     }     var chartSeries : ChartSeriesData     struct ChartData: Codable, Identifiable, Hashable {         var id = UUID()         let chartMonth: String         let chartSales: String     }     init() {         chartCategory = ""         chartSeries = ChartSeriesData(chartEntry: [ChartData(chartMonth: "01", chartSales: "10.0") ] )     } } How do I populate ChartSeriesData? I thought I could just add the following: However coding this way there is no append method. extension ChartSeriesRow {     func addRow(chartRow: ChartSeriesData){          ChartSeriesRow.ChartSeriesData.chartEntry.append(contentsOf: chartRow)     } }
Replies
2
Boosts
0
Views
855
Activity
Nov ’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?
Replies
4
Boosts
0
Views
1.4k
Activity
Nov ’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
Replies
5
Boosts
0
Views
1k
Activity
Sep ’23
Deleting CloudKit data
I have been testing an app which uses cloudKit with SWIFTDATA and after testing for several months my 200GB iCloud store is showing 168GB for iCloud Drive. Now my iCloud drive is only 22.6GB so the rest of the 168GB must be data from my app. Also, I have function in my app to delete all iCloud Data which I thought that should clean up iCloud storage but it does not. I tried resetting the Develop Environment but no change to iCloud data. Also I have several other containers in iCloud created while getting iCloud working which I would like to delete but I understand you can’t. https://forums.developer.apple.com/forums/thread/45251?answerId=788694022#788694022 Bottom line cloudkit console has been pretty much useless for me and I need a way to manage (delete containers and data). Am I missing something?
Replies
1
Boosts
0
Views
1.1k
Activity
Jun ’24
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] = [] }
Replies
7
Boosts
0
Views
1.4k
Activity
Aug ’24
NavlgationLink Code not working on macOS Sequoia
This code which works fine on macOS Sonoma but on Sequoia the navigationLinks do not work? VStack { Text("Application Global Values") .font(.largeTitle) .fontWeight(.bold) .padding(.bottom, 10) Text("Select each of the Descriptors, enter the values and when done then Tap on (Add/Save)") .font(.title3) .foregroundColor(.secondary) List { NavigationLink("Enter Core Descriptors", destination: CoreView(systemSettings: $systemSettings)) .padding() // Add padding to create some space inside the border // .background(Color.white) // Optional: Add a background color if needed // .border(Color.red, width: 2) // Add a red border with a specified thickness .overlay( RoundedRectangle(cornerRadius: 10) // Specify the corner radius for rounded corners .stroke(Color.red, lineWidth: 2) // Define the color and thickness of the border ) SetupDivider(thickness: 3) NavigationLink("Enter Counters Descriptors", destination: CountersView(systemSettings: $systemSettings)) .padding() // .background(Color.white) .overlay( RoundedRectangle(cornerRadius: 10) // Specify the corner radius for rounded corners .stroke(Color.red, lineWidth: 2) // Define the color and thickness of the border ) SetupDivider(thickness: 3) NavigationLink("Create Custom Descriptors", destination: UserFieldsView(userFields: $userFields)) .padding() // .background(Color.white) .overlay( RoundedRectangle(cornerRadius: 10) // Specify the corner radius for rounded corners .stroke(Color.red, lineWidth: 2) // Define the color and thickness of the border ) SetupDivider(thickness: 3) NavigationLink("View All Descriptors", destination: DefaultDetailView(userFields: $userFields, systemSettings: $systemSettings)) .padding() // .background(Color.white) .overlay( RoundedRectangle(cornerRadius: 10) // Specify the corner radius for rounded corners .stroke(Color.red, lineWidth: 2) // Define the color and thickness of the border ) SetupDivider(thickness: 3) }
Replies
1
Boosts
0
Views
434
Activity
Aug ’24
Swiftui Table statement conditional table columns
Is it possible to have conditional table columns for a swifui Table statement? Like for this code TableColumn("Image") { artPiece in if let imageData = artPiece.artImage.first, let image = UIImage(data: imageData!) { Image(uiImage: image) .resizable() .frame(width: 50, height: 50) } else { Image(systemName: "photo") .resizable() .frame(width: 50, height: 50) } } .customizationID("Image") TableColumn("Name", value: \.artName) .customizationID("Name") TableColumn ("Art ID", value: \.artPieceID) { artPiece in Text(String(artPiece.artPieceID)) } .customizationID("Art ID") have a conditional TableColumn for this part of my SWIFTDATA model var artDefinedFields: [ArtDefinedFields] = [] or if I change the variable string array to this var artDefinedFields: [ArtDefinedFields] = Array(repeating: ArtDefinedFields(), count: 10), initialize the array with "None" and only create a TableColumn when there is aArtDeginedFields value other than "None"
Replies
3
Boosts
0
Views
665
Activity
Aug ’24
How to save an Image to NsData object and then retrieve.
My environment is as follows: Xcode 12, macOS BS developing a macOS app. I have an IBOutlet from a IB window as @IBOutlet weak var imageView: NSImageView! So, I want to store imageView to a NSData object and then save the NSData object in my UserDefaults. Once I saved the Image in my UserDefaults I need to be able to decode or retrieve the image for use in other parts of the app. How is this done? Also, I have seen some cautions about converting an Image to NSData object and retrieving. It seems the retrieved image may not be 100% as it was originally. Is this true and if so why? Thanks
Replies
2
Boosts
0
Views
1.2k
Activity
Jun ’21
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?
Replies
4
Boosts
0
Views
1.2k
Activity
Mar ’22
How to Activate Printer Panel
How do you activate the Printer Panel using a toolbar printer Icon in a macOS app like you get when I select File -> Print (CMD-P)? This is in a tableView view based screen. I have connected the first responder to "print:" thinking this might work but the printer Icon in the toolbar remains grayed-out. Also, tried connecting it to a @IBAction func but it still is grayed out. I am using Xcode 13 and 14 beta
Replies
0
Boosts
0
Views
388
Activity
Jul ’22