Post

Replies

Boosts

Views

Activity

Any way to keep app running while keep main window hidden?
I tried many ways but it seems I just cannot get it working. // AppDelegate func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { true // false does not work either } // MainWC func windowShouldClose(_ sender: NSWindow) -> Bool { print(#function) if sender === NSApp.mainWindow { print("is main window") sender.setIsVisible(false) return false } return true } Once I hide the main window (using setIsVisible or orderOut) the app quits; even if I return false from applicationShouldTerminateAfterLastWindowClosed, NSApp.mainWindow will become nil.
1
0
776
Mar ’24
NSMutableDictionary removeAllObjects does not free up used memory!
I have a custom Objective-C ObjectCache class that utilized NSMutableDictionary to store named objects (specifically large NSImage objects). The class has a maxItems property and clear method, which worked fine. - (void)clear { @synchronized(_cache) { [_cache removeAllObjects]; } } But yesterday I received a customer feedback complaining one of my app consumes up to 24GB memory. I verified that on my M1 Mac mini, and it's true. Even after calling clear method, memory usage shown in both Xcode debugger panel and Activity Monitor remains the same. It did work before. Once I close a picture gallery window by calling clear method, memory usage dropped immediately as shown in Activity Monitor. I suspect that this is a bug in ARM architecture. Does anyone else have same problem?
1
0
900
Mar ’24
How let scroll event 'sink' to parent view?
I have an uncommon scenario here. outer tableview +--------------------------+ | column 1| inner tableview| +--------------------------+ Now most often the out tableview has many rows and vertical scrollbar visible. When user try to scroll vertically in the inner tableview but it has no vertical scrollbar (because it has only a few items), I want the scroll event sink into its parent view or better outer tableview, so that user does not have to move cursor to first column in outer tableview and scrolls. Is this possible?
1
0
846
Mar ’24
When to call noteHeightOfRows when cell view changes size?
I have a tableview with a column which has an inner tableview. I want to change height of the outer tableview to match the height of the inner tableview. outerTableView.reloadData() let range = outerTableView.rows(in: summaryTableView.superview!.visibleRect) outerTableView.noteHeightOfRows(withIndexesChanged: IndexSet(integersIn: range.lowerBound..<range.upperBound)) The above code will cause an exception: WARNING: NSTableView detected a rowView was requested from inside of the -heightOfRow delegate method. That is not supported! ( 0 CoreFoundation 0x000000019093eccc __exceptionPreprocess + 176 1 libobjc.A.dylib 0x0000000190426788 objc_exception_throw + 60 2 AppKit 0x000000019420be98 -[NSTableRowData _availableRowViewWhileUpdatingAtRow:] + 0 3 AppKit 0x000000019425a470 -[NSTableView viewAtColumn:row:makeIfNecessary:] + 32
1
1
658
Mar ’24
How activate window correctly using activationPolicy
I have the following code: + (BOOL)activateWindow:(NSWindow*)window { if (NSApp.activationPolicy != NSApplicationActivationPolicyRegular) [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; if (window) { [NSApp activate]; //if (window.isMiniaturized) [window deminiaturize:nil]; [window makeKeyAndOrderFront:nil]; } return YES; } + (BOOL)hideWindowFromDock:(NSWindow*)window { if (NSApp.activationPolicy != NSApplicationActivationPolicyProhibited) [NSApp setActivationPolicy:NSApplicationActivationPolicyProhibited]; window.isVisible = NO; return YES; } I hide app main window by setting NSApplicationActivationPolicyProhibited if it is minimized or being closed. The code worked most of the time. But since upgrading to Sonoma, sometimes it won't correctly activate main window. The window icon reappears in the dock, but the window won't show up. I have to click on the window icon again to let it 'order front'. Sometimes, I observe a very weird behavior of the window being activated. It 'order front' and then disappears and re-appears.
1
0
876
Jun ’24
Playground starts slowly or never runs
I am a little hesitant to ask this question because it's been years, during which I hoped it's just a specific problem of my own computer or Xcode version. I'm not sure if it's only me alone with this problem. First time run of any playground project is extremely slow (after I open it); sometimes it just never runs with the build indicator circling forever). This is true for objc or swift playgrounds, or different machines, different Xcode versions, different OS versions. Can anyone help?
2
0
1.7k
Feb ’22
IB_DESIGNABLE and dylib problem
My app has 2 dylibs linked, in build settings run path is set to "@executable_path/../Frameworks" and a copy file rule is also there. The app runs fine for years now (in App Store). But once I turn on IB_DESIGNABLE for a custom view, IB reports errors like below: It seems IB tries to load the dylibs from somewhere in Xcode.app. What should I do in order to get IB_DESIGNABLE to work in IB?
2
0
735
Apr ’23
No Info.plist in newly created project
It seem Apple is forcing developers to use new Xcode 14.3 and Ventura. I am having various rudimentary problems with Xcode 14.2. Today I created a new project and was surprised to find out that there is Info.plist in the project. I have to copy one from an older project. I am wondering if Xcode 14.3 does the same thing (not creating Info.plist). Or I am quite behind the trend because I had not updated my apps for more than a year. EDIT: Why PRODUCT_BUNDLE_IDENTIFIER is invalid?
2
0
26k
Apr ’23
CFBundleIdentifier not match?
I submitted a test package and got the following email: ITMS-90345: Metadata/Info.plist Mismatch - The value for bundle_identifier in the metadata.xml file does not match the value for CFBundleIdentifier in test [net.neolib.test.pkg/Payload/test.app]. I really don't have any idea what's wrong. It's a simple (almost blank) app with nearly no modification (except linked with a dylib). What is the metadata.xml? I cannot find it in my test project.
2
0
852
Apr ’23
Weird: let statement leads to nil
I have not touched Swift code for more than a year. My skills become rusty. I am not sure what stupid errors I made in the following code: extension Bundle { func readResourceFile(_ filename: String) -> String? { if let fileUrl = self.resourceURL?.appendingPathComponent(filename, isDirectory: false) { return try? String(contentsOf: fileUrl) } return nil } } class MyVC { //... @IBAction func testButton_click(_ sender: Any) { Task.init { await self.test1() } } func test1() async { var loaded = false do { let result = try await self.webView.evaluateJavaScript("typeof(jQuery)") loaded = result as? String == "function" } catch { self.statusLabel.stringValue = "error: \(error)" } if (loaded) { await self.runUserScript(self.input.string) return } let scriptFiles = ["jQuery.js", "Scriptlets.js"] var count = 0 for scriptFile in scriptFiles { print("Loading \(scriptFile)") do { if let script = Bundle.main.readResourceFile(scriptFile) { try await self.webView.evaluateJavaScript(script) print("Loaded \(scriptFile)") count += 1 } } catch { self.statusLabel.stringValue = "error: \(error)" } } } The line if let script = Bundle.main.readResourceFile(scriptFile) { succeeds but script still is nil and causes app crash in next line self.webView.evaluateJavaScript(script). Bundle.main.readResourceFile(scriptFile) is working if I run this line elsewhere. EDIT: When I click on the I button in debugging on variable script I get: (String) script = <no location, value may have been optimized out> However, I can print(script) and the output is correct.
2
0
561
Apr ’23