Post

Replies

Boosts

Views

Created

How check unreferenced headers in Objective-C?
In other IDEs on many popular platforms, developers have the ability to analyze unreferenced header files in source code (either visually or thru warnings), like below: // sourcefile.c #include <file1.h> // file2.h is not referenced in this source code file, so the following line would be grayed out in a well known iDE #include <file2.h> Is this possible in Xcode?
0
0
552
Jun ’24
IDE generated *varname problem
When Xcode IDE inserts IBOutlet or autocompletes method signatures, it places the * char next to the var name: @property (weak) IBOutlet NSButton *aButton; - (NSString *)someMethod:(NSString *)param1 { } But my convention is put the * char right after the type name: @property (weak) IBOutlet NSButton* aButton; - (NSString*)someMethod:(NSString*)param1 { } Is there anyway to tell Xcode to follow my convention?
0
0
688
Jun ’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
913
Jun ’24
Cannot get NSTimer working in another thread
I need to create timers in another thread (not on main): @implementation AppDelegate { NSThread* _worker; } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { _worker = [[NSThread alloc] initWithTarget:self selector:@selector(main) object:nil]; [_worker start]; } - (void)main { [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timer_tick:) userInfo:nil repeats:YES]; [NSThread sleepForTimeInterval:INFINITY]; NSLog(@"**********************"); } - (void)timer_tick:(NSTimer*)timer { NSLog(@"%@", NSThread.currentThread); } The timer never gets fired. What's wrong with my code?
2
0
830
May ’24
Memory leak with [NSMutableData appendData:]
Instruments reveals that the following simple code leaks memory on each delegate invoke: - (void)start { [_urlSession dataTaskWithURL:_url]; } - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data { [_data appendData:data]; } I don't have any clue on this leak, it should not happen. What should I do to avoid this?
2
0
977
Apr ’24
Difference between private and fileprivate?
It seems I can declare variables like below in a source file: private let var1 = 1234 fileprivate let var2 = "abcd" class MyClass { // ... } So what's the difference between the 2 vars here?
Replies
2
Boosts
0
Views
1.3k
Activity
Jul ’24
How reset assistant editor position?
I don't know when/why my assistant editor opened on bottom. I don't have any idea how to get it back to its original position (on right side). It's annoying.
Replies
2
Boosts
0
Views
808
Activity
Jul ’24
How check unreferenced headers in Objective-C?
In other IDEs on many popular platforms, developers have the ability to analyze unreferenced header files in source code (either visually or thru warnings), like below: // sourcefile.c #include <file1.h> // file2.h is not referenced in this source code file, so the following line would be grayed out in a well known iDE #include <file2.h> Is this possible in Xcode?
Replies
0
Boosts
0
Views
552
Activity
Jun ’24
How round an NSDate to midnight (00:00) of the day?
NSDate* now = [NSDate date]; // How get midnight time of now?
Replies
2
Boosts
0
Views
838
Activity
Jun ’24
IDE generated *varname problem
When Xcode IDE inserts IBOutlet or autocompletes method signatures, it places the * char next to the var name: @property (weak) IBOutlet NSButton *aButton; - (NSString *)someMethod:(NSString *)param1 { } But my convention is put the * char right after the type name: @property (weak) IBOutlet NSButton* aButton; - (NSString*)someMethod:(NSString*)param1 { } Is there anyway to tell Xcode to follow my convention?
Replies
0
Boosts
0
Views
688
Activity
Jun ’24
Unit test /tmp path question
In XCTestCase, I write data to a file "/tmp/somefile", but the file does not exist in /tmp when I do ls in Terminal. Where is the file actually created?
Replies
2
Boosts
0
Views
920
Activity
Jun ’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.
Replies
1
Boosts
0
Views
913
Activity
Jun ’24
Cannot get NSTimer working in another thread
I need to create timers in another thread (not on main): @implementation AppDelegate { NSThread* _worker; } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { _worker = [[NSThread alloc] initWithTarget:self selector:@selector(main) object:nil]; [_worker start]; } - (void)main { [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timer_tick:) userInfo:nil repeats:YES]; [NSThread sleepForTimeInterval:INFINITY]; NSLog(@"**********************"); } - (void)timer_tick:(NSTimer*)timer { NSLog(@"%@", NSThread.currentThread); } The timer never gets fired. What's wrong with my code?
Replies
2
Boosts
0
Views
830
Activity
May ’24
How know if windowWillClose: is invoked by X button click
Is there any way to tell if the user clicked X button in windowWillClose delegate method? - (void)windowWillClose:(NSNotification *)notification
Replies
2
Boosts
0
Views
859
Activity
May ’24
Memory leak with [NSMutableData appendData:]
Instruments reveals that the following simple code leaks memory on each delegate invoke: - (void)start { [_urlSession dataTaskWithURL:_url]; } - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data { [_data appendData:data]; } I don't have any clue on this leak, it should not happen. What should I do to avoid this?
Replies
2
Boosts
0
Views
977
Activity
Apr ’24
How keep NSWindow always on top other windows?
Is there any way to keep an NSWindow always on top of other windows (inside an app)? I want to create a "preview" window for pictures and videos with it not taking up space in the main window.
Replies
2
Boosts
0
Views
1.5k
Activity
Mar ’24
How read/write String Catalog files (xcstrings)?
Does Swift/objc provide builtin support for reading/writing xcstrings, like PropertyListEncoder/PropertyListDecoder?
Replies
0
Boosts
0
Views
768
Activity
Mar ’24
NSEvent.scrollingDeltaY and "natural scrolling"
Does "natural scrolling" system preference affect NSEvent.scrollingDeltaY? BTW, I find that "natural scrolling" on my Sonoma (Mac mini m1) stops working; turning on/off has no effect when I scroll in Finder app.
Replies
0
Boosts
0
Views
629
Activity
Mar ’24
How reset the Collection list in font panel to default?
I accidentally removed the Fixed Width preset item in the font panel (by dragging it out). Is there any way to get it back?
Replies
0
Boosts
0
Views
734
Activity
Mar ’24
How tell if NSTableView is already displaying its last row entirely?
I am no expert at coordinate systems. I am kind of aware I can use its enclosingScrollView but don't know the details. Any suggestions would be appreciated.
Replies
2
Boosts
0
Views
736
Activity
Mar ’24