Post

Replies

Boosts

Views

Activity

Reply to How to sort NSTableView Date Column?
I changed the code to convert date to an integer and that worked for me as well changed to a different column. let dateFormatter = DateFormatter()             dateFormatter.dateFormat = "YYYYMMdd"             dateFormatter.locale = Locale(identifier: "en_US_POSIX") invoices.sort { (p1, p2) -> Bool in                 let p1Date: Int? = Int(dateFormatter.string(from: p1.invoiceDateCreated!))                 let p2Date: Int? =  Int(dateFormatter.string(from: p2.invoiceDateCreated!))                 guard let id1 = p1Date, let id2 = p2Date else { return true }                 if ascending {                     return id1 < id2                 } else {                     return id2 < id1                 }             }
Topic: UI Frameworks SubTopic: AppKit Tags:
Sep ’22
Reply to NSPredicate format for date comparison
Either of the following two lines can cause the error: predicate = NSPredicate(format: "invoiceNumber contains %@ OR invoiceCustName contains %@ OR invoiceStatus contains %@ OR invoiceDateCreated >= %@",searchString,searchString,searchString,searchString) predicate = NSPredicate(format: "invoiceDateCreated >= %@", searchString as CVarArg) The problem I am having is with the operator >=, I not sure how to filter my table with the date type. The CONTAINS operator only works with strings. I want to be able to filter on a date type variable. Also, is this meant to say items? invoiceCount = "Found (items.count ) Invoices" ... No, it should say invoices - good catch
Topic: UI Frameworks SubTopic: AppKit Tags:
Sep ’22
Reply to NSPredicate format for date comparison
I figured this out. I had to create a date from the search string to use in the predicate>>> Here is the working code:     @objc func invoiceSearch(sender:NSSearchField) {   let searchString = sender.stringValue         let dateFormatter = DateFormatter()         dateFormatter.dateFormat = "YYYYMMdd"         var dateTemplate: String = "20000101"         var dateSearch: String = ""         var dateEndSearch: String = ""         dateFormatter.locale = Locale(identifier: "en_US_POSIX")         var predicate:NSPredicate = NSPredicate()         if searchString.isEmpty {             invoices = self.backUpInvoices         }         else{       // search field contains data             if searchString.isContainsLetters == false {     // If false must be a date search (Numerics or -)                 dateSearch = dateTemplate                    // Code to handle a begin and end date in                 if searchString.count < 9 {                  // the format YYYYMMDD-YYYYMMDD initially end date is                     dateSearch.removeFirst(searchString.count) // set to current date                     dateSearch = searchString + dateSearch                     searchBeginDate = dateFormatter.date(from: dateSearch)!                 }                 else {                     if searchString.count > 9 {                         dateSearch.removeFirst(searchString.count-9)                         dateEndSearch = searchString                         dateEndSearch.removeFirst(9)                         dateSearch = dateEndSearch + dateSearch                         searchEndDate = dateFormatter.date(from: dateSearch)!                     }                 }             }             if (invoiceSearchField.cell as? NSSearchFieldCell)?.placeholderString == "All" {                 predicate = NSPredicate(format: "invoiceNumber contains %@ OR invoiceCustName contains %@ OR invoiceStatus contains %@ OR invoiceDateCreated >= %@ AND invoiceDateCreated < %@",searchString,searchString,searchString,searchBeginDate as NSDate, searchEndDate as NSDate)             }             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 >= %@ AND invoiceDateCreated < %@", searchBeginDate as NSDate, searchEndDate as NSDate)             }             invoices = (self.backUpInvoices as NSArray).filtered(using: predicate) as! [Invoice]         }
Topic: UI Frameworks SubTopic: AppKit Tags:
Sep ’22
Reply to How to Initialize a structure with in a class?
Thanks Claude, follow up question.. 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)     } }
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’22
Reply to How to add an IBAction to a macOS tableView Cell
import Cocoa class CustomTableCell: NSTableCellView {     @IBOutlet weak var userNameLabel: NSTextField!     @IBOutlet weak var roleLabel: NSTextField!    @IBOutlet var testTextView: NSTextView!     override func draw(_ dirtyRect: NSRect) {         super.draw(dirtyRect)         // Drawing code here.     }     @IBAction func emailButton(_ sender: Any) {         // Email user     } } I was first trying to add a @IBAction for a scrollview and when I control drag the scrollview to the CustomTableCell file I could not create and @IBAction. It is like having a scrollview object inside a scrollable table view is not allowed. So, I was not able to create an action to get the contents of the scrollview in the ViewController code. Much less creating code to pass to the viewController the contents of the scrollView text entered. I sent a offline demo project to illustrate what I am saying. Thanks for your help on this.
Topic: UI Frameworks SubTopic: AppKit Tags:
Nov ’22
Reply to macOS Xcode 14.2 app applicationwillterminate function is not called
I got it working. I did need to set Application can be killed immediately when user is shutting down or logging out" setting to NO to the target using the INFO tab but I had a coding error implementing applicationWillTerminate. So, here is how my app delegate looks now. import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate {         func applicationWillFinishLaunching(_ notification: Notification) {     }     func applicationDidFinishLaunching(_ aNotification: Notification) {         // Insert code here to initialize your application           //    try! DatabaseManager.setup(for: NSApp)     }     func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {         return true     }     func applicationWillTerminate(_ Notification: Notification) {         // Insert code here to tear down your application         getPrefs()         if paymePref.prefAutoBackup == "Yes" {             backupDataBase()         }     } }
Topic: UI Frameworks SubTopic: AppKit Tags:
Jan ’23
Reply to How to sort NSTableView Date Column?
I changed the code to convert date to an integer and that worked for me as well changed to a different column. let dateFormatter = DateFormatter()             dateFormatter.dateFormat = "YYYYMMdd"             dateFormatter.locale = Locale(identifier: "en_US_POSIX") invoices.sort { (p1, p2) -> Bool in                 let p1Date: Int? = Int(dateFormatter.string(from: p1.invoiceDateCreated!))                 let p2Date: Int? =  Int(dateFormatter.string(from: p2.invoiceDateCreated!))                 guard let id1 = p1Date, let id2 = p2Date else { return true }                 if ascending {                     return id1 < id2                 } else {                     return id2 < id1                 }             }
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Sep ’22
Reply to NSPredicate format for date comparison
Either of the following two lines can cause the error: predicate = NSPredicate(format: "invoiceNumber contains %@ OR invoiceCustName contains %@ OR invoiceStatus contains %@ OR invoiceDateCreated >= %@",searchString,searchString,searchString,searchString) predicate = NSPredicate(format: "invoiceDateCreated >= %@", searchString as CVarArg) The problem I am having is with the operator >=, I not sure how to filter my table with the date type. The CONTAINS operator only works with strings. I want to be able to filter on a date type variable. Also, is this meant to say items? invoiceCount = "Found (items.count ) Invoices" ... No, it should say invoices - good catch
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Sep ’22
Reply to NSPredicate format for date comparison
The problem seems to be with the variable invoiceDateCreated because it is a foundation date (@objc) and not NSDate object. Any ideas how to change this to get it working?
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Sep ’22
Reply to NSPredicate format for date comparison
I figured this out. I had to create a date from the search string to use in the predicate>>> Here is the working code:     @objc func invoiceSearch(sender:NSSearchField) {   let searchString = sender.stringValue         let dateFormatter = DateFormatter()         dateFormatter.dateFormat = "YYYYMMdd"         var dateTemplate: String = "20000101"         var dateSearch: String = ""         var dateEndSearch: String = ""         dateFormatter.locale = Locale(identifier: "en_US_POSIX")         var predicate:NSPredicate = NSPredicate()         if searchString.isEmpty {             invoices = self.backUpInvoices         }         else{       // search field contains data             if searchString.isContainsLetters == false {     // If false must be a date search (Numerics or -)                 dateSearch = dateTemplate                    // Code to handle a begin and end date in                 if searchString.count < 9 {                  // the format YYYYMMDD-YYYYMMDD initially end date is                     dateSearch.removeFirst(searchString.count) // set to current date                     dateSearch = searchString + dateSearch                     searchBeginDate = dateFormatter.date(from: dateSearch)!                 }                 else {                     if searchString.count > 9 {                         dateSearch.removeFirst(searchString.count-9)                         dateEndSearch = searchString                         dateEndSearch.removeFirst(9)                         dateSearch = dateEndSearch + dateSearch                         searchEndDate = dateFormatter.date(from: dateSearch)!                     }                 }             }             if (invoiceSearchField.cell as? NSSearchFieldCell)?.placeholderString == "All" {                 predicate = NSPredicate(format: "invoiceNumber contains %@ OR invoiceCustName contains %@ OR invoiceStatus contains %@ OR invoiceDateCreated >= %@ AND invoiceDateCreated < %@",searchString,searchString,searchString,searchBeginDate as NSDate, searchEndDate as NSDate)             }             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 >= %@ AND invoiceDateCreated < %@", searchBeginDate as NSDate, searchEndDate as NSDate)             }             invoices = (self.backUpInvoices as NSArray).filtered(using: predicate) as! [Invoice]         }
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Sep ’22
Reply to structured editing popover with Xcode 14.1 beta 3
I am going thru some of the apple videos on swiftUI. [https://developer.apple.com/tutorials/swiftui?ref=madewithvuejs.com ) Also, it is cmd left click not cmd-right click.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’22
Reply to structured editing popover with Xcode 14.1 beta 3
You can get to this menu by CMD-Click in the code Not sure why you can not get this from CMD-Click on the canvas?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’22
Reply to structured editing popover with Xcode 14.1 beta 3
The canvas needs to be in selectable view, This is set with the icon at the bottom left of the canvas. Once this is done the popup menu appears when you press CMD-Click.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’22
Reply to How to Initialize a structure with in a class?
Thanks Claude, follow up question.. 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)     } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to How to populate an array within a Class Instance?
Thanks again Claude, you have been very helpful. I think I am finally understanding to store data you need an instance of an object.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to How to add an IBAction to a macOS tableView Cell
import Cocoa class CustomTableCell: NSTableCellView {     @IBOutlet weak var userNameLabel: NSTextField!     @IBOutlet weak var roleLabel: NSTextField!    @IBOutlet var testTextView: NSTextView!     override func draw(_ dirtyRect: NSRect) {         super.draw(dirtyRect)         // Drawing code here.     }     @IBAction func emailButton(_ sender: Any) {         // Email user     } } I was first trying to add a @IBAction for a scrollview and when I control drag the scrollview to the CustomTableCell file I could not create and @IBAction. It is like having a scrollview object inside a scrollable table view is not allowed. So, I was not able to create an action to get the contents of the scrollview in the ViewController code. Much less creating code to pass to the viewController the contents of the scrollView text entered. I sent a offline demo project to illustrate what I am saying. Thanks for your help on this.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to How to add an IBAction to a macOS tableView Cell
Thanks Claude, could not have done it without your help.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to How to change the text color for SwiftUI Chart's legend text?
Thanks for the reply, I have been doing some research on secondaryLabelColor and can't find any examples as well as attempting to add it to my swiftUI view but not really sure how to code. Do you have any usage examples of this? Also, how did you go about figuring out the legend color is driven by secondaryLabelColor. Thanks
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to Remove XCode settings Document Types
Seems to be still the case with Xcode 14.2. However I don't have a info.plist. Any ideas how to delete?
Replies
Boosts
Views
Activity
Jan ’23
Reply to macOS Xcode 14.2 app applicationwillterminate function is not called
After reviewing some of the doc mentioned above, I did not see  "sudden termination" but I added "Application can be killed immediately when user is shutting down or logging out" setting to NO to the target using the INFO tab but still applicationWillTerminate function is not being called. Any ideas how to fix?
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Jan ’23
Reply to macOS Xcode 14.2 app applicationwillterminate function is not called
I got it working. I did need to set Application can be killed immediately when user is shutting down or logging out" setting to NO to the target using the INFO tab but I had a coding error implementing applicationWillTerminate. So, here is how my app delegate looks now. import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate {         func applicationWillFinishLaunching(_ notification: Notification) {     }     func applicationDidFinishLaunching(_ aNotification: Notification) {         // Insert code here to initialize your application           //    try! DatabaseManager.setup(for: NSApp)     }     func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {         return true     }     func applicationWillTerminate(_ Notification: Notification) {         // Insert code here to tear down your application         getPrefs()         if paymePref.prefAutoBackup == "Yes" {             backupDataBase()         }     } }
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Jan ’23