Post

Replies

Boosts

Views

Activity

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 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 Drawing an NSImage using COCOA Drawing
Found the following code on gitHub extension NSImage {    /// Create a CIImage using the best representation available    ///    /// - Returns: Converted image, or nil    func asCIImage() -> CIImage? {       if let cgImage = self.asCGImage() {          return CIImage(cgImage: cgImage)       }       return nil    }    /// Create a CGImage using the best representation of the image available in the NSImage for the image size    ///    /// - Returns: Converted image, or nil    func asCGImage() -> CGImage? {       var rect = NSRect(origin: CGPoint(x: 0, y: 0), size: self.size)       return self.cgImage(forProposedRect: &rect, context: NSGraphicsContext.current, hints: nil)     } } extension CIImage {    /// Create a CGImage version of this image    ///    /// - Returns: Converted image, or nil    func asCGImage(context: CIContext? = nil) -> CGImage? {       let ctx = context ?? CIContext(options: nil)       return ctx.createCGImage(self, from: self.extent)    }    /// Create an NSImage version of this image    /// - Parameters:    ///   - pixelSize: The number of pixels in the result image. For a retina image (for example), pixelSize is double repSize    ///   - repSize: The number of points in the result image    /// - Returns: Converted image, or nil    #if os(macOS)    @available(macOS 10, *)    func asNSImage(pixelsSize: CGSize? = nil, repSize: CGSize? = nil) -> NSImage? {       let rep = NSCIImageRep(ciImage: self)       if let ps = pixelsSize {          rep.pixelsWide = Int(ps.width)          rep.pixelsHigh = Int(ps.height)       }       if let rs = repSize {          rep.size = rs       }       let updateImage = NSImage(size: rep.size)       updateImage.addRepresentation(rep)       return updateImage    }    #endif } extension CGImage {    /// Create a CIImage version of this image    ///    /// - Returns: Converted image, or nil    func asCIImage() -> CIImage {       return CIImage(cgImage: self)    }    /// Create an NSImage version of this image    ///    /// - Returns: Converted image, or nil    func asNSImage() -> NSImage? {       return NSImage(cgImage: self, size: .zero)    } } Added the following two lines to get what I needed  let cgimage: CGImage? = image.asCGImage() // Here comes the picture NSGraphicsContext.current?.cgContext.draw(cgimage!, in: dirtyRect)
Topic: UI Frameworks SubTopic: AppKit Tags:
Aug ’22
Reply to How to add headers programmatically to NSTableView
I got the answer to this from apple support. It seems the tableView must part of a scrollView for the headers to appear. So I removed any reference to the explicit creation of a table header view and I added the following code to get this working: let scrollView = NSScrollView() scrollView.documentView = tableViewForPrint stackView.addArrangedSubview(scrollView)
Topic: UI Frameworks SubTopic: AppKit Tags:
Aug ’22
Reply to How to see current window?
Maybe another way to accomplish what I want is...If when you change focus of a window an event is posted in the now focused window gets control. In other words can the focused window tell it just got the focus. Is there way to do this?
Topic: UI Frameworks SubTopic: AppKit Tags:
Aug ’22
Reply to How to call function in NSViewController?
You are right it compiled fine with the reference and creating and instance, but did throw an exception due to the IBAction used some CustViewController properties. So, using notification I was able to get it working. Also, why do you think the delegation may be the cleanest way? Thanks for the help.
Topic: UI Frameworks SubTopic: AppKit Tags:
Aug ’22
Reply to How to call function in NSViewController?
Thanks for the reply! I tried it and I get the following: let printAction CustViewController.printCustomers(self) Instance member 'printCustomers' cannot be used on type 'CustViewController': did you mean to use a value of this type instead? The window controller I am referring to is the main window where as the view controller is from a separate/different window controller/view controller. My objective is to have a main printer control action which would control which printout would be generated when a CMD-P is pressed. One thing from another post mentioned I would need an instance just with contentViewController. Not sure how to code this as well?
Topic: UI Frameworks SubTopic: AppKit Tags:
Aug ’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
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 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 Drawing an NSImage using COCOA Drawing
Found the following code on gitHub extension NSImage {    /// Create a CIImage using the best representation available    ///    /// - Returns: Converted image, or nil    func asCIImage() -> CIImage? {       if let cgImage = self.asCGImage() {          return CIImage(cgImage: cgImage)       }       return nil    }    /// Create a CGImage using the best representation of the image available in the NSImage for the image size    ///    /// - Returns: Converted image, or nil    func asCGImage() -> CGImage? {       var rect = NSRect(origin: CGPoint(x: 0, y: 0), size: self.size)       return self.cgImage(forProposedRect: &rect, context: NSGraphicsContext.current, hints: nil)     } } extension CIImage {    /// Create a CGImage version of this image    ///    /// - Returns: Converted image, or nil    func asCGImage(context: CIContext? = nil) -> CGImage? {       let ctx = context ?? CIContext(options: nil)       return ctx.createCGImage(self, from: self.extent)    }    /// Create an NSImage version of this image    /// - Parameters:    ///   - pixelSize: The number of pixels in the result image. For a retina image (for example), pixelSize is double repSize    ///   - repSize: The number of points in the result image    /// - Returns: Converted image, or nil    #if os(macOS)    @available(macOS 10, *)    func asNSImage(pixelsSize: CGSize? = nil, repSize: CGSize? = nil) -> NSImage? {       let rep = NSCIImageRep(ciImage: self)       if let ps = pixelsSize {          rep.pixelsWide = Int(ps.width)          rep.pixelsHigh = Int(ps.height)       }       if let rs = repSize {          rep.size = rs       }       let updateImage = NSImage(size: rep.size)       updateImage.addRepresentation(rep)       return updateImage    }    #endif } extension CGImage {    /// Create a CIImage version of this image    ///    /// - Returns: Converted image, or nil    func asCIImage() -> CIImage {       return CIImage(cgImage: self)    }    /// Create an NSImage version of this image    ///    /// - Returns: Converted image, or nil    func asNSImage() -> NSImage? {       return NSImage(cgImage: self, size: .zero)    } } Added the following two lines to get what I needed  let cgimage: CGImage? = image.asCGImage() // Here comes the picture NSGraphicsContext.current?.cgContext.draw(cgimage!, in: dirtyRect)
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to How to add headers programmatically to NSTableView
I got the answer to this from apple support. It seems the tableView must part of a scrollView for the headers to appear. So I removed any reference to the explicit creation of a table header view and I added the following code to get this working: let scrollView = NSScrollView() scrollView.documentView = tableViewForPrint stackView.addArrangedSubview(scrollView)
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to How to see current window?
Maybe another way to accomplish what I want is...If when you change focus of a window an event is posted in the now focused window gets control. In other words can the focused window tell it just got the focus. Is there way to do this?
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to How to call function in NSViewController?
You are right it compiled fine with the reference and creating and instance, but did throw an exception due to the IBAction used some CustViewController properties. So, using notification I was able to get it working. Also, why do you think the delegation may be the cleanest way? Thanks for the help.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to How to call function in NSViewController?
Thanks for the reply! I tried it and I get the following: let printAction CustViewController.printCustomers(self) Instance member 'printCustomers' cannot be used on type 'CustViewController': did you mean to use a value of this type instead? The window controller I am referring to is the main window where as the view controller is from a separate/different window controller/view controller. My objective is to have a main printer control action which would control which printout would be generated when a CMD-P is pressed. One thing from another post mentioned I would need an instance just with contentViewController. Not sure how to code this as well?
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to General Question using swiftCharts?
Thanks I will give this a try!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to Xcode 13.2 and Github - No Packages listed
I installed 13.2.1 but still don't see any packages in the GitHub source.
Replies
Boosts
Views
Activity
Dec ’21
Reply to How to save an Image to NsData object and then retrieve.
Thanks, for your answer.. I have decided to save the image to a file.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Jun ’21