Post

Replies

Boosts

Views

Activity

Reply to Jump to Definition on Symbols in a Swift Framework's Gigantic Generated "Header"?
Oh my, the SwitfUI generated "Interface" is a single 85833 lines and there's no "Jump to Definition" menu item when you right click on any symbols. And because almost everything is Protocols in Swift you can't reason about the API using this generated interface because when you right click on a protocol you can't jump the definition of the protocol. You got 85 thousand lines to scroll through to find it. Does everyone really like working like this? Is it really that hard to write a header file? Just asking.
Topic: Programming Languages SubTopic: Swift Tags:
Oct ’23
Reply to Customize NSToolbar context menu on Sonoma
It is important. I'm fully aware the way we do it is a hack and it was not that unexpected to see it stop working at some point... Then instead of doing this: NSView * theContentView = myWindow.contentView; NSMenu * theCustomizeMenu = theContentView.superview.menu; You can try can try enumerating subviews from the content view superview until you find it. Ideally you should isolate this hack in a category because the code is really nasty. Something like this: //Public @interface NSWindow (FindCustomizeToolbarMenu) -(nullable NSMenu*)findToolbarContextMenu; @end **//Put all the in the .m** #import "NSWindow+FindCustomizeToolbarMenu.h" #import <objc/runtime.h> @interface NSMenu (NSToolbarMenuMarkerHack) @property (nonatomic) BOOL isCustomizeToolbarMenu; @end @implementation NSMenu (NSToolbarMenuMarkerHack) static char const * const ToolbarMenuHackKey = "ToolbarMenuHackKey"; -(BOOL)isCustomizeToolbarMenu { NSNumber *result = objc_getAssociatedObject(self, ToolbarMenuHackKey); return (result != nil) ? result.boolValue : NO; } -(void)setIsCustomizeToolbarMenu:(BOOL)isCustomizeToolbarMenu { objc_setAssociatedObject(self, ToolbarMenuHackKey, @(isCustomizeToolbarMenu), OBJC_ASSOCIATION_RETAIN_NONATOMIC); } @end @implementation NSWindow (FindCustomizeToolbarMenu) -(NSMenu*)searchForCustomizeToolbarMenuInSubviews:(NSArray<NSView*>*)subviews { if (subviews.count == 0) { return nil; } NSMenu *foundMenu = nil; for (NSView *aSubview in subviews) { NSMenu *theMenu = aSubview.menu; if (theMenu.isCustomizeToolbarMenu || [theMenu.itemArray.lastObject.title isEqualToString:@"Customize Toolbar…"]) // <--Should compare a localized string! If you append on the found menu later this check will fail because "Customize Toolbar…" will no longer be the last object! { foundMenu.isCustomizeToolbarMenu = YES; //Mark it in case you mutate the menu later and "Customize Toolbar…" is not the last menu item. foundMenu = theMenu; break; } } //Found it? if (foundMenu != nil) { return foundMenu; } else { //Didn't find it. Dig through descendant views. for (NSView *aSubviewToDigIn in subviews) { NSMenu *nested = [self searchForCustomizeToolbarMenuInSubviews:aSubviewToDigIn.subviews]; if (nested != nil) { foundMenu = nested; break; } } return foundMenu; } } -(NSMenu*)findToolbarContextMenu { NSView *theContentView = self.contentView; NSView *contentViewSuperview = theContentView.superview; NSMutableArray *theSuperViewSubviews = [contentViewSuperview.subviews mutableCopy]; [theSuperViewSubviews removeObject:theContentView]; //Don't need to search the content view since we know it doesn't have it. NSMenu *foundMenu = [self searchForCustomizeToolbarMenuInSubviews:theSuperViewSubviews]; return foundMenu; } This is very ugly and fragile and untested so inspect the code and use at your own risk. But in theory you should be able to do something like this using the category: NSMenu *toolbarMenu = [self.window findToolbarContextMenu]; [toolbarMenu addItemWithTitle:@"CUSTOM" action:nil keyEquivalent:@""]; You could try filing a Feedback and ask Apple to improve the API but I have my doubts about that. You'd at least have to wait a year for them to add it and there's a good chance they never will.
Topic: UI Frameworks SubTopic: AppKit Tags:
Oct ’23
Reply to Jump to Definition on Symbols in a Swift Framework's Gigantic Generated "Header"?
FWIW command+clicking on a symbol works sometimes even though there is no "Jump to Definition" context menu item. I think "Jump to Definition" would be useful since so much is scattered about. IMHO it would be better if these generated framework interfaces would instead create separate files grouped logically (in the way you would organize them if you were creating the header files yourself) instead of just dumping everything in gigantic generated interface file with protocols and extensions galore and you gotta hop all over the place to get a sense of an API.
Topic: Programming Languages SubTopic: Swift Tags:
Oct ’23
Reply to Enable WKWebView Web Inspector Under Mac Catalyst?
It's better than nothing but still not as good as being able to open the web inspector from the WKWebView itself because: We have to switch to Safari to get the Web Inspector. and 2) You don't get an "Inspect Element..." menu item when you right click to launch the web inspector in the WKWebView itself.
Topic: Safari & Web SubTopic: General Tags:
Oct ’23
Reply to Mac Catalyst Menu Bar/Toolbar Actions Not Validating Properly After Changing Active Windows
After returning to this Catalyst project after some time away from it this issue is still occurring in Xcode 15 Sonoma. Basically the responder chain and the focus system breaks after making another app the frontmost app (menu bar owning) and then navigating back my app (making my app frontmost, menubar owning, etc). When I make my app frontmost again on Mac the focus system stops working. Tab key does nothing (it is expected to change focus) and many menu bar actions are not validating. @rttCanada Yes. It does seem like this could be related to NSUIViewToolbarItem. I have a NSUIViewToolbarItem subclass which wraps a UIButton subclass (in the system style). My subclass of UIButton just overrides canBecomeFocused and returns NO (because otherwise tabbing unexpectedly moved focus to this button in the toolbar which seemed wrong). //Wrapped in a NSUIViewToolbarItem subclass @implementation SystemStyledButtonInToolbarDontFocusOnMePleaseItMakesNoSenseUseTheMenuBarOrKeyboardShortcutToInvokeThisActionIfYouWantToGoMouseFree -(BOOL)canBecomeFocused { return NO; } @end My toolbar is customizable and if I remove this button from the toolbar it seems to fix the problem (though more testing is needed to say for sure).
Topic: UI Frameworks SubTopic: UIKit Tags:
Oct ’23
Reply to Mac Catalyst Menu Bar/Toolbar Actions Not Validating Properly After Changing Active Windows
All they would need to do to fix this is to use a subclass on UIWindow for the scene that is created by NSUIViewToolbarItem (_UIViewHostingScene which is a subclass of UIWindowScene) and return NO from -canBecomeKeyWindow and -canBecomeFocused. Can confirm this by using Objective-C superpowers. Just swizzle -canBecomeKeyWindow and -canBecomeFocused and return NO for both these methods. -(BOOL)jjj_canBecomeKeyWindow { BOOL originalImp = [self jjj_canBecomeKeyWindow]; if ([self.windowScene isKindOfClass:NSClassFromString(@"_UIViewHostingScene")]) { //NEVER, EVER. return NO; } return originalImp; } -(BOOL)jjj_canBecomeFocused { BOOL originalImp = [self jjj_canBecomeFocused]; if ([self.windowScene isKindOfClass:NSClassFromString(@"_UIViewHostingScene")]) { //don't EVER! return NO; } return originalImp; } And then the responder chain/focus system doesn't break when you switch back to your app window.
Topic: UI Frameworks SubTopic: UIKit Tags:
Oct ’23
Reply to Code-level support ticket usage
I don't speak for Apple but from my experience I usually get credited back the ticket if they think the issue I'm reporting is a system bug initially (before talking to an Apple engineer) and they don't think there is a workaround they can advise. For example I opened a TSI recently and I got an email "No workaround is available" and I got my TSI credited back. Sometimes they won't necessarily think your issue relates to a system bug but then after talking to an engineer they may realize it is. In these cases I don't think they will refund your ticket once you start communication with an engineer (but I'm just speaking on my own experience I have no idea what their official policy is). They may suggest a workaround in these cases (but may not have one to offer either). Then everything ends with you filing a Bug Report and you wait but in my experience none of my bugs ever got fixed and I never hear from them again.
Oct ’23