Post

Replies

Boosts

Views

Activity

Reply to Where is the Web entry for app iCloud SDK
I have found where the Web entry is. I have to enable CloudKit service in project settings. Now I have another problem - I accidentally created several database containers (long time ago out of curiosity by clicking a button that says "Enable ClouldKit" or something similar). But I cannot find a way to delete the garbage items. The only way is to hide them in the CloudKit management Web UI.
Feb ’24
Reply to Any way to keep app running while keep main window hidden?
Ah, I found out why, though it's a little embarrassing... After so many years, I realized that NSApp.mainWindow is dynamic - it can be any window that has the key focus! I have to create a global variable to keep instance of the initial window (as designed in main storyboard). var mainWindow: NSWindow? // Set in MainWC.windowDidLoad class AnotherWC: NSWindowController, NSWindowDelegate { override func windowDidLoad() { super.windowDidLoad() print(self.className, #function) } func windowShouldClose(_ sender: NSWindow) -> Bool { print(self.className, #function) return true } func windowWillClose(_ notification: Notification) { print(self.className, #function) print(mainWindow ?? "mainWindow is nil") mainWindow?.orderFront(nil) } }
Topic: UI Frameworks SubTopic: AppKit Tags:
Mar ’24
Reply to What's the unit in NSView coordinate system
Maybe my question is too general. I have a need to calculate all width of an NSTableView. However, I found that total width of all columns is far less than NSTableView.bound.width: let width = tableView.tableColumns.reduce(0) { ac, col in ac + col.width } print(width, tableView.bounds.width) This is true even I manually adjust last column so that it fills the gap between the column and tableview right border. -----------| <- table right border last column| -----------| So I assume NSTableColumn.width and NSView.bounds.width are using different units.
Topic: UI Frameworks SubTopic: AppKit Tags:
Mar ’24
Reply to How let scroll event 'sink' to parent view?
I found a solution myself, after days of researching and experiments. It's related to another question "How tell if NSTableView is already displaying its last row entirely?". // For the inner tableview's scrollview class MyScrollView: NSScrollView { var onScrollWheel: EventHandler! override func scrollWheel(with event: NSEvent) { super.scrollWheel(with: event) // In onScrollWheel, determine if vertical scrollbar is hidden or at top/bottom, // then delegate this event to the outer tableview: // outerTableView.scrollWheel(with: event) onScrollWheel?(event) } }
Topic: UI Frameworks SubTopic: AppKit Tags:
Mar ’24
Reply to When to call noteHeightOfRows when cell view changes size?
I did much search on the web and found no answer. The only clue to my question is that I have use another "template" tableview that is identical to the inner tableview. Finally I devised a working solution, I posted here for the purpose of helping others who may have the same/similar problem. Note there is a little trick about calculating the actually row height - you have to include height of the template tableview's header view. func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat { if tableView is DetailsTableView { return tableView.rowHeight } if let rowHeight = rowHeights[row] { return rowHeight } let item = categorizedItems[row] if sizingTableView == nil { var objects: NSArray! detailsNib!.instantiate(withOwner: nil, topLevelObjects: &objects) for object in objects { if let sizingCellView = object as? DetailsCellView { sizingTableView = sizingCellView.tableView sizingTableView.delegate = self sizingTableView.dataSource = self sizingTableView.isHidden = true sizingTableView.enclosingScrollView?.setFrameSize(NSSize.zero) self.view.addSubview(sizingTableView) break } } } print("<", sizingTableView.bounds.height) sizingTableView.row = row sizingTableView.files = item.files sizingTableView.reloadData() print(">", sizingTableView.bounds.height) var rowHeight = sizingTableView.bounds.height + (sizingTableView.headerView?.bounds.height ?? 0.0) + summaryTableView.intercellSpacing.height rowHeights[row] = rowHeight if rowHeight > MaxRowHeight { let trailingHeight = (sizingTableView.bounds.height / Double(item.files.count)) * Double(TrailingRowCount) if rowHeight - MaxRowHeight < trailingHeight { // Try reserve height for some rows to let scrollbar look more natural. rowHeight = max(0, MaxRowHeight - trailingHeight) } else { rowHeight = MaxRowHeight } } return max(rowHeight, summaryTableView.rowHeight) }
Topic: UI Frameworks SubTopic: AppKit Tags:
Mar ’24
Reply to Memory leak with [NSMutableData appendData:]
Finally I have to re-invent the wheel to solve this mysterious memory leak which I cannot control without the wheel. I am not sure if it is too bold to declare that NSData has serious problems with memory footprint, but... After I devised my own memory management facility (a smart buffer class), the memory footprint drops drastically and stops growing continuously. This is observed for several days.
Topic: Programming Languages SubTopic: General Tags:
May ’24
Reply to Can't get Xcode to parse the code in one file in editor
Xcode (starting from version 11, maybe) is buuuuuuuuuuuggy. It has big features, but fails miserably on small or tiny functionalities. You can try right-click the file and select "View As->Source Code". If this does not work either, then remove the file and re-add it back (at least this worked for me once or twice).
Replies
Boosts
Views
Activity
Jan ’24
Reply to "zero length data" error
Anyway, I found out the cause. The error is thrown when initializing XMLDocument with an empty string: let xd = try XMLDocument(xmlString: "")
Topic: Programming Languages SubTopic: General Tags:
Replies
Boosts
Views
Activity
Feb ’24
Reply to Where is the Web entry for app iCloud SDK
I have found where the Web entry is. I have to enable CloudKit service in project settings. Now I have another problem - I accidentally created several database containers (long time ago out of curiosity by clicking a button that says "Enable ClouldKit" or something similar). But I cannot find a way to delete the garbage items. The only way is to hide them in the CloudKit management Web UI.
Replies
Boosts
Views
Activity
Feb ’24
Reply to Unit test environment in scheme is gone?
Please ignore my question. It should be always like this because I set "Host Application" to None in the unit test target.
Replies
Boosts
Views
Activity
Mar ’24
Reply to Any way to keep app running while keep main window hidden?
Ah, I found out why, though it's a little embarrassing... After so many years, I realized that NSApp.mainWindow is dynamic - it can be any window that has the key focus! I have to create a global variable to keep instance of the initial window (as designed in main storyboard). var mainWindow: NSWindow? // Set in MainWC.windowDidLoad class AnotherWC: NSWindowController, NSWindowDelegate { override func windowDidLoad() { super.windowDidLoad() print(self.className, #function) } func windowShouldClose(_ sender: NSWindow) -> Bool { print(self.className, #function) return true } func windowWillClose(_ notification: Notification) { print(self.className, #function) print(mainWindow ?? "mainWindow is nil") mainWindow?.orderFront(nil) } }
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Mar ’24
Reply to What's the unit in NSView coordinate system
Maybe my question is too general. I have a need to calculate all width of an NSTableView. However, I found that total width of all columns is far less than NSTableView.bound.width: let width = tableView.tableColumns.reduce(0) { ac, col in ac + col.width } print(width, tableView.bounds.width) This is true even I manually adjust last column so that it fills the gap between the column and tableview right border. -----------| <- table right border last column| -----------| So I assume NSTableColumn.width and NSView.bounds.width are using different units.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Mar ’24
Reply to How tell if NSTableView is already displaying its last row entirely?
At last, I found the answer myself, again. The answer lies in NSScroller.floatValue which inherited from NSControl. let shouldDelegate = { if let scroller = scrollView.verticalScroller { return scroller.isHidden || scroller.floatValue == 0 || scroller.floatValue == 1.0 } return true }()
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Mar ’24
Reply to How let scroll event 'sink' to parent view?
I found a solution myself, after days of researching and experiments. It's related to another question "How tell if NSTableView is already displaying its last row entirely?". // For the inner tableview's scrollview class MyScrollView: NSScrollView { var onScrollWheel: EventHandler! override func scrollWheel(with event: NSEvent) { super.scrollWheel(with: event) // In onScrollWheel, determine if vertical scrollbar is hidden or at top/bottom, // then delegate this event to the outer tableview: // outerTableView.scrollWheel(with: event) onScrollWheel?(event) } }
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Mar ’24
Reply to When to call noteHeightOfRows when cell view changes size?
I did much search on the web and found no answer. The only clue to my question is that I have use another "template" tableview that is identical to the inner tableview. Finally I devised a working solution, I posted here for the purpose of helping others who may have the same/similar problem. Note there is a little trick about calculating the actually row height - you have to include height of the template tableview's header view. func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat { if tableView is DetailsTableView { return tableView.rowHeight } if let rowHeight = rowHeights[row] { return rowHeight } let item = categorizedItems[row] if sizingTableView == nil { var objects: NSArray! detailsNib!.instantiate(withOwner: nil, topLevelObjects: &objects) for object in objects { if let sizingCellView = object as? DetailsCellView { sizingTableView = sizingCellView.tableView sizingTableView.delegate = self sizingTableView.dataSource = self sizingTableView.isHidden = true sizingTableView.enclosingScrollView?.setFrameSize(NSSize.zero) self.view.addSubview(sizingTableView) break } } } print("<", sizingTableView.bounds.height) sizingTableView.row = row sizingTableView.files = item.files sizingTableView.reloadData() print(">", sizingTableView.bounds.height) var rowHeight = sizingTableView.bounds.height + (sizingTableView.headerView?.bounds.height ?? 0.0) + summaryTableView.intercellSpacing.height rowHeights[row] = rowHeight if rowHeight > MaxRowHeight { let trailingHeight = (sizingTableView.bounds.height / Double(item.files.count)) * Double(TrailingRowCount) if rowHeight - MaxRowHeight < trailingHeight { // Try reserve height for some rows to let scrollbar look more natural. rowHeight = max(0, MaxRowHeight - trailingHeight) } else { rowHeight = MaxRowHeight } } return max(rowHeight, summaryTableView.rowHeight) }
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Mar ’24
Reply to How keep NSWindow always on top other windows?
Again, I found it myself. override func windowDidLoad() { super.windowDidLoad() window?.level = .floating }
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Mar ’24
Reply to DSA trader status update in App Store Connect
I also have the same question here.
Replies
Boosts
Views
Activity
Mar ’24
Reply to Memory leak with [NSMutableData appendData:]
Finally I have to re-invent the wheel to solve this mysterious memory leak which I cannot control without the wheel. I am not sure if it is too bold to declare that NSData has serious problems with memory footprint, but... After I devised my own memory management facility (a smart buffer class), the memory footprint drops drastically and stops growing continuously. This is observed for several days.
Topic: Programming Languages SubTopic: General Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to Unit test /tmp path question
It's strange. When I tried again, I found the file in /tmp: - (void)test { NSError* error; [@"abc123" writeToFile:@"/tmp/testfile" atomically:NO encoding:NSUTF8StringEncoding error:&error]; if (error) NSLog(@"%@", error); }
Replies
Boosts
Views
Activity
Jun ’24
Reply to How reset assistant editor position?
Yeah... I found it myself after 15 minutes of digging. It's right there under the "Assistant" menu item.
Replies
Boosts
Views
Activity
Jul ’24
Reply to Any virtual machine software on M1/arm?
Great news for me and other individual developers! Broadcom acquired VMware.com and now VMware Workstation Pro/Fusion Pro are free for personal use.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jul ’24