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.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
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?
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?
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.
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.
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 tell if the user clicked X button in windowWillClose delegate method?
- (void)windowWillClose:(NSNotification *)notification
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?
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?
NSDate* now = [NSDate date];
// How get midnight time of now?
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.
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?
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.
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.
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?
Topic:
Developer Tools & Services
SubTopic:
Xcode