Post

Replies

Boosts

Views

Activity

Error with Xcode 15 beta 5
I am getting the following error on this line of code @Query(sort: \.id, order: .reverse) private var artList: [ArtInventory] Cannot infer key path type from context; consider explicitly specifying a root type So, I select fix and then the line of code then look like this @Query(sort: \<#Root#>.id, order: .reverse) private var artList: [ArtInventory] with this error Invalid component of Swift key path Some seems to have changed with the @Query macro in beta 5, which now needs a root type, but not sure how to proceed. Any ideas how to fix?
1
1
1.6k
Jul ’23
How to get control from a combo box selection?
Using a combo box after a selection I want to get control to take some actions based on the selection after press tab or return in the field. I have tried a few controls like the one below: // textShouldEndEditing     func control(_ control: NSControl, textShouldEndEditing fieldEditor: NSText) - Bool {         print(#function,control.tag) But the above control only gets control if the field is edited. I want control once tab, an item selected or return is pressed while on the filed. How is this done?
2
0
605
Mar ’21
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
819
Mar ’21
TableView not populating?
I have the following code in a viewController: extension InvoicesDetailController: NSTableViewDelegate {     fileprivate enum CellIdentifiers {         static let lineItemLabelCell = "lineItemLabelCell"         static let lineItemDescCell = "lineItemDescCell"         static let lineItemAmountCell = "lineItemAmountCell"         static let lineItemQtyCell = "lineItemQtyCell"     }     fileprivate enum fieldIdentifiers {         static let lineItemLabel = "lineItemLabel"         static let lineItemDesc = "lineItemDesc"         static let lineItemAmount = "lineItemAmount"         static let lineItemQty = "lineItemQty"     }   func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) - NSView? {         let currentItem = invoiceItems[row]         var text: String = ""         var cellIdentifier: String = ""         let currentColumn = tableColumn?.identifier.rawValue         if currentColumn == fieldIdentifiers.lineItemLabel {             text = currentItem.lineItemLabel!             cellIdentifier = CellIdentifiers.lineItemLabelCell         }         if currentColumn == fieldIdentifiers.lineItemDesc {             text = currentItem.lineItemDesc!             cellIdentifier = CellIdentifiers.lineItemDescCell         }         if currentColumn == fieldIdentifiers.lineItemAmount {             text = currentItem.lineItemDesc!             cellIdentifier = CellIdentifiers.lineItemAmountCell         }         if currentColumn == fieldIdentifiers.lineItemQty {             text = currentItem.lineItemQty!             cellIdentifier = CellIdentifiers.lineItemQtyCell         }         if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: cellIdentifier), owner: self) as? NSTableCellView {             print(cell.textField?.stringValue)             cell.textField?.stringValue = text             print(text, cell.textField?.stringValue)             return cell         }         return nil     } I have used this code (similar code in other places and it works fine, however in this case the tableView Cells are not being populated. When I look at this code using debugger the line if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: cellIdentifier), owner: self) as? NSTableCellView always sets cell to nil? Since I don't see anything wrong with code I suspect there is an issue with the IB? Any ideas how to fix or how to debug further?
1
0
608
Mar ’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
1k
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
738
Aug ’22
How to add headers programmatically to NSTableView
I have created programmatically a NSTableView with a couple of columns, this table view has 3 columns and I want to set headers for the columns to accomplish the same thing as you get when you selected headers in IB. I looked for some examples, found a few things but not really work for me. How is this done. It seems like this should be easy to code. This is an example of one of the examples I found. let headerCell = CustomTableHeaderCell.init(textCell: "123123") // let font = NSFont(name: "Arial", size: 22.0) // headerCell.stringValue = "firstname" // headerCell.font = font self.tableView.tableColumns[0].headerCell = headerCell But CustomTableHeaderCell is not found. How is this done?
Topic: UI Frameworks SubTopic: AppKit Tags:
1
0
1.1k
Aug ’22
macOS TableView dynamic row height?
Environment is macOS Monterey Xcode 13. Is there a way to change the behavior of a macOS NSTableView to have the row height change based on the contents of a column. As an example when populating the column data and the width of the content exceeds the width of the column to have the content wrap to an additional line, which of course the row height would have to change then as well. If so, how can this be done? Thanks
1
0
1.3k
Aug ’22
NSGraphicsContext.current expression is ambiguous without more context
I am using the code below to learn more about drawing but I am getting an ambiguous error on the line not sure how to resolve this. Please advise how to code this. Thanks let context = NSGraphicsContext.current()?.cgContext  override func draw(_ dirtyRect: NSRect) {         super.draw(dirtyRect)        ** let context = NSGraphicsContext.current()?.cgContext**         let length = CGPoint(x: 100, y: 100)         let p1 = CGPoint(x: 200, y: 200)         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 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: 0)         q.draw(at: center, withAttributes: attr as [NSAttributedString.Key : Any])     } }
1
0
881
Aug ’22
Where does SwiftData store the data?
I understand by default SwiftData uses SQLite database but it can be configured to persist data in XML, binary and even in-memory databases. Does anybody know where SwiftData the SQLite database is located?
Replies
3
Boosts
3
Views
6.6k
Activity
Jan ’24
Error with Xcode 15 beta 5
I am getting the following error on this line of code @Query(sort: \.id, order: .reverse) private var artList: [ArtInventory] Cannot infer key path type from context; consider explicitly specifying a root type So, I select fix and then the line of code then look like this @Query(sort: \<#Root#>.id, order: .reverse) private var artList: [ArtInventory] with this error Invalid component of Swift key path Some seems to have changed with the @Query macro in beta 5, which now needs a root type, but not sure how to proceed. Any ideas how to fix?
Replies
1
Boosts
1
Views
1.6k
Activity
Jul ’23
Companion Xcode project
Don't see a link to download the Xcode project, starter and complete? How can I get it? Thanks Bob
Replies
2
Boosts
1
Views
810
Activity
Jun ’23
Xcode 12 macOS not showing app icon
Anybody else having problems with app icon on Xcode 12 not showing up for a macOS app?
Replies
1
Boosts
1
Views
3.8k
Activity
Jun ’21
Xcode 14.2 Find and Replace in Project not working
The find and replace in project is not working for me in Xcode 14.2 on Ventura 13.2. When I enter the find text as well as the replace text the "Replace" and "Replace All" buttons remained grayed out. Is this a bug with Xcode or am I missing something? Please advise.
Replies
0
Boosts
1
Views
638
Activity
Jan ’23
Create a new Window
Using Interface Builder with Xcode 11 I have created two windows, when I activate the second window it opens as a tab in the main window. How do I change this to start a second window instead of a tab?
Replies
3
Boosts
0
Views
3.3k
Activity
Mar ’21
How to get control from a combo box selection?
Using a combo box after a selection I want to get control to take some actions based on the selection after press tab or return in the field. I have tried a few controls like the one below: // textShouldEndEditing     func control(_ control: NSControl, textShouldEndEditing fieldEditor: NSText) - Bool {         print(#function,control.tag) But the above control only gets control if the field is edited. I want control once tab, an item selected or return is pressed while on the filed. How is this done?
Replies
2
Boosts
0
Views
605
Activity
Mar ’21
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
Replies
3
Boosts
0
Views
819
Activity
Mar ’21
TableView not populating?
I have the following code in a viewController: extension InvoicesDetailController: NSTableViewDelegate {     fileprivate enum CellIdentifiers {         static let lineItemLabelCell = "lineItemLabelCell"         static let lineItemDescCell = "lineItemDescCell"         static let lineItemAmountCell = "lineItemAmountCell"         static let lineItemQtyCell = "lineItemQtyCell"     }     fileprivate enum fieldIdentifiers {         static let lineItemLabel = "lineItemLabel"         static let lineItemDesc = "lineItemDesc"         static let lineItemAmount = "lineItemAmount"         static let lineItemQty = "lineItemQty"     }   func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) - NSView? {         let currentItem = invoiceItems[row]         var text: String = ""         var cellIdentifier: String = ""         let currentColumn = tableColumn?.identifier.rawValue         if currentColumn == fieldIdentifiers.lineItemLabel {             text = currentItem.lineItemLabel!             cellIdentifier = CellIdentifiers.lineItemLabelCell         }         if currentColumn == fieldIdentifiers.lineItemDesc {             text = currentItem.lineItemDesc!             cellIdentifier = CellIdentifiers.lineItemDescCell         }         if currentColumn == fieldIdentifiers.lineItemAmount {             text = currentItem.lineItemDesc!             cellIdentifier = CellIdentifiers.lineItemAmountCell         }         if currentColumn == fieldIdentifiers.lineItemQty {             text = currentItem.lineItemQty!             cellIdentifier = CellIdentifiers.lineItemQtyCell         }         if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: cellIdentifier), owner: self) as? NSTableCellView {             print(cell.textField?.stringValue)             cell.textField?.stringValue = text             print(text, cell.textField?.stringValue)             return cell         }         return nil     } I have used this code (similar code in other places and it works fine, however in this case the tableView Cells are not being populated. When I look at this code using debugger the line if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: cellIdentifier), owner: self) as? NSTableCellView always sets cell to nil? Since I don't see anything wrong with code I suspect there is an issue with the IB? Any ideas how to fix or how to debug further?
Replies
1
Boosts
0
Views
608
Activity
Mar ’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.
Replies
5
Boosts
0
Views
1k
Activity
May ’21
General Question using swiftCharts?
I have a macOS app which was built using Xcode 13 and storyboard. I want to add swiftCharts to the app. Can I add swiftCharts code to this app and not have to migrate the storyboard UI to swiftUI? How can this be done? Thanks
Replies
2
Boosts
0
Views
1k
Activity
Jun ’22
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:
Replies
5
Boosts
0
Views
738
Activity
Aug ’22
How to add headers programmatically to NSTableView
I have created programmatically a NSTableView with a couple of columns, this table view has 3 columns and I want to set headers for the columns to accomplish the same thing as you get when you selected headers in IB. I looked for some examples, found a few things but not really work for me. How is this done. It seems like this should be easy to code. This is an example of one of the examples I found. let headerCell = CustomTableHeaderCell.init(textCell: "123123") // let font = NSFont(name: "Arial", size: 22.0) // headerCell.stringValue = "firstname" // headerCell.font = font self.tableView.tableColumns[0].headerCell = headerCell But CustomTableHeaderCell is not found. How is this done?
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
1
Boosts
0
Views
1.1k
Activity
Aug ’22
macOS TableView dynamic row height?
Environment is macOS Monterey Xcode 13. Is there a way to change the behavior of a macOS NSTableView to have the row height change based on the contents of a column. As an example when populating the column data and the width of the content exceeds the width of the column to have the content wrap to an additional line, which of course the row height would have to change then as well. If so, how can this be done? Thanks
Replies
1
Boosts
0
Views
1.3k
Activity
Aug ’22
NSGraphicsContext.current expression is ambiguous without more context
I am using the code below to learn more about drawing but I am getting an ambiguous error on the line not sure how to resolve this. Please advise how to code this. Thanks let context = NSGraphicsContext.current()?.cgContext  override func draw(_ dirtyRect: NSRect) {         super.draw(dirtyRect)        ** let context = NSGraphicsContext.current()?.cgContext**         let length = CGPoint(x: 100, y: 100)         let p1 = CGPoint(x: 200, y: 200)         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 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: 0)         q.draw(at: center, withAttributes: attr as [NSAttributedString.Key : Any])     } }
Replies
1
Boosts
0
Views
881
Activity
Aug ’22