Post

Replies

Boosts

Views

Activity

Swift if statement with multiple conditions
I just want some experts on Swift to confirm that the following syntaxes are equivalent: if a > b, c > d { } if a > b && c > d { } I consulted "The Swift Programming Lanugage (version 5.7)" but the book does not cover this issue. But I believe it's true because my tests show they are the same.
2
0
977
Feb ’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
968
May ’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
817
May ’24
Need Objective-C translation of DispatchSource.makeFileSystemObjectSource
I came across a useful repo on GitHub: https://github.com/GianniCarlo/DirectoryWatcher/blob/master/Sources/DirectoryWatcher/DirectoryWatcher.swift self.queue = DispatchQueue.global() self.source = DispatchSource.makeFileSystemObjectSource(fileDescriptor: descriptor, eventMask: .write, queue: self.queue) self.source?.setEventHandler { [weak self] in self?.directoryDidChange() } self.source?.setCancelHandler() { close(descriptor) } self.source?.resume() How do I translate this to OC version? I have an app that was written in OC and I plan to incorporate this directory watcher into the project.
2
0
1k
Jul ’24
Zombie Xcode problem
I have a weird problem with Xcode v15.4. For some unknown reasons, it sometimes becomes a zombie process - I cannot even quit it using CMD+Q, nor can I close open projects. I have to forcibly kill the process using Activity Monitor. The problem will mostly strike after a long time of idle time (hours or even days). Does anyone else have this same problem? Is there known workaround? BTW, when it becomes a zombie process, another related com.apple.dt.SKAgent process will begin consuming much CPU time forever.
2
0
535
Sep ’24
Swift if statement with multiple conditions
I just want some experts on Swift to confirm that the following syntaxes are equivalent: if a > b, c > d { } if a > b && c > d { } I consulted "The Swift Programming Lanugage (version 5.7)" but the book does not cover this issue. But I believe it's true because my tests show they are the same.
Replies
2
Boosts
0
Views
977
Activity
Feb ’24
Unit test environment in scheme is gone?
I use ProcessInfo.processInfo.environment["key"] to get test parameters, but all of a sudden I could not find the UI like below: In the screenshot above, the 2 environment variables were actually what I entered for the unit test target. I don't have any idea why they were moved there! Any similar problems?
Replies
2
Boosts
0
Views
1.7k
Activity
Mar ’24
Where can I found a list of codes for NSEvent.keyCode
According to the doc: The value returned is the same as the value returned in the kEventParamKeyCode when using Carbon Events. So where can I find kEventParamKeyCode?
Replies
2
Boosts
0
Views
1.2k
Activity
Feb ’25
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
730
Activity
Mar ’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
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
968
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
847
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
817
Activity
May ’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
911
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
825
Activity
Jun ’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
800
Activity
Jul ’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
Need Objective-C translation of DispatchSource.makeFileSystemObjectSource
I came across a useful repo on GitHub: https://github.com/GianniCarlo/DirectoryWatcher/blob/master/Sources/DirectoryWatcher/DirectoryWatcher.swift self.queue = DispatchQueue.global() self.source = DispatchSource.makeFileSystemObjectSource(fileDescriptor: descriptor, eventMask: .write, queue: self.queue) self.source?.setEventHandler { [weak self] in self?.directoryDidChange() } self.source?.setCancelHandler() { close(descriptor) } self.source?.resume() How do I translate this to OC version? I have an app that was written in OC and I plan to incorporate this directory watcher into the project.
Replies
2
Boosts
0
Views
1k
Activity
Jul ’24
Zombie Xcode problem
I have a weird problem with Xcode v15.4. For some unknown reasons, it sometimes becomes a zombie process - I cannot even quit it using CMD+Q, nor can I close open projects. I have to forcibly kill the process using Activity Monitor. The problem will mostly strike after a long time of idle time (hours or even days). Does anyone else have this same problem? Is there known workaround? BTW, when it becomes a zombie process, another related com.apple.dt.SKAgent process will begin consuming much CPU time forever.
Replies
2
Boosts
0
Views
535
Activity
Sep ’24
Xcode Documentation window eats up much CPU time
After upgrading to Xcode 16.3, whenever I open the Documentation window, Xcode started CPU hungry mode, forever. Does anyone else have the same experience as me? Is there any known remedy so far?
Replies
2
Boosts
0
Views
155
Activity
Apr ’25