The run loop itself doesn't actually "turn" at a predictable rate. Depending on how your app is architected and the overall app state, it's entirely possible for an app to go seconds or even minutes without the main thread ever running.
Doesn't appear to be what's going on in this case. I made this dumb little test which can easily reproduce the issue (sorry can't get code to format well on these forums).
+(MachoManURLTester*)sharedTester
{
static MachoManURLTester *sharedTester = nil;
static dispatch_once_t token;
dispatch_once(&token,^{
sharedTester = [[self alloc]init];
});
return sharedTester;
}
-(void)startURLTrashDance
{
NSAssert(NSThread.currentThread.isMainThread, @"Main thread only.");
NSFileManager *fm = [NSFileManager defaultManager];
NSURL *wrapperDir = [[NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES] URLByAppendingPathComponent:NSUUID.UUID.UUIDString isDirectory:YES];
if (![fm createDirectoryAtURL:wrapperDir withIntermediateDirectories:YES attributes:nil error:nil])
{
NSLog(@"Test failed");
return;
}
//[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:@[wrapperDir]];
NSURL *untitledFour = [wrapperDir URLByAppendingPathComponent:@"Untitled 4" isDirectory:YES];
if (![fm createDirectoryAtURL:untitledFour withIntermediateDirectories:YES attributes:nil error:nil])
{
NSLog(@"Test failed");
return;
}
NSLog(@"Created untitled 4.");
NSURL *resultingURL = nil;
if (![fm trashItemAtURL:untitledFour resultingItemURL:&resultingURL error:nil])
{
NSLog(@"trash failed");
return;
}
NSLog(@"Moved Untitled 4 to the trash.");
[self performSelector:@selector(replaceTrashedURL:) withObject:untitledFour afterDelay:1.0];
[self performSelector:@selector(compareBothURLS:) withObject:@[untitledFour,resultingURL] afterDelay:4.0];
}
-(void)replaceTrashedURL:(NSURL*)originalURL
{
NSFileManager *fm = [NSFileManager defaultManager];
if ([fm createDirectoryAtURL:originalURL withIntermediateDirectories:YES attributes:nil error:nil])
{
NSLog(@"Recreated Untitled 4");
}
}
-(void)compareBothURLS:(NSArray<NSURL*>*)twoURLsArray
{
NSLog(@"4 seconds is up - let's check");
NSFileManager *fm = [NSFileManager defaultManager];
NSURL *untitledFour = twoURLsArray.firstObject;
NSURL *resultingURL = twoURLsArray.lastObject;
// Uncomment these fixes the relationship check:
//[untitledFour removeCachedResourceValueForKey:NSURLFileResourceIdentifierKey];
//[resultingURL removeCachedResourceValueForKey:NSURLFileResourceIdentifierKey];
NSURLRelationship relationship;
NSError *error = nil;
if ([fm getRelationship:&relationship ofDirectoryAtURL:untitledFour toItemAtURL:resultingURL error:&error])
{
if (relationship == NSURLRelationshipSame)
{
NSLog(@"NSURLRelationshipSame: %@ - %@?",untitledFour,resultingURL);
}
else if (relationship == NSURLRelationshipContains)
{
NSLog(@"NSURLRelationshipContains");
}
else if (relationship == NSURLRelationshipOther)
{
NSLog(@"NSURLRelationshipOther");
}
else {
NSLog(@"Unknown");
}
}
else
{
NSLog(@"Error reading relationship: %@",error);
}
}
@end
Just use that class and do this in a test program.
MachoManURLTester *URLTester = [MachoManURLTester sharedTester];
[URLTester startURLTrashDance];
And to answer your earlier question, YES the file reference urls do collide.