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?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
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.
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?
NSDate* now = [NSDate date];
// How get midnight time of now?
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?
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?
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.
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?
Is there any way to tell if the user clicked X button in windowWillClose delegate method?
- (void)windowWillClose:(NSNotification *)notification
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?
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.
Does Swift/objc provide builtin support for reading/writing xcstrings, like PropertyListEncoder/PropertyListDecoder?
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.
I accidentally removed the Fixed Width preset item in the font panel (by dragging it out).
Is there any way to get it back?
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.