Thursday, 6 December 2018

macos - How did XCode/OSX do that? Moved an XCode project to another location. XCode automatically knew where it was located


Just a quick bit of background. I am a long time Windows, C# developer and for a new project for my employer, I've had to transition to OSX and begin learning iOS development. In other words, I'm still quite new to the Mac/OSX environment.


Earlier today I decided that I'd close out of XCode and re-organize my testing and learning project, and projects that I've created in XCode that hold assets I will most likely need to reuse. When I fired XCode back up, I was surprised to see that all of my recent projects were still in the Recents list and they were pointing to the new file location! Sweet!


How did XCode know where my projects were located? Is a function of the Operating System, the File System or does XCode have some form of intelligence built into the system to detect these type of questions?



Answer



This functionality is available from pretty much every application's File » Open Recent menu provided by the convenience methods in LaunchServices/LSSharedFilesList.h (which is also the name of the plist files storing this information, e.g. ~/Library/Preferences/com.apple.Preview.LSSharedFilesList.plist).


These entries contain a serialized NSData (presumably), which you can copy and write to a file e.g. using a hex editor. They contain the full path to the file, the volume name the file is on, a UUID, and some additional information I currently cannot make sense if. I assume that the UUID is used to resolve the file reference if needed.




NSURLs can be converted to file references that can be resolved later, even when a file has moved. This answer on StackOverflow has more technical information.




I'm not sure, but HFS+ has inodes that uniquely identify a file. The NSURL functionality is possibly implemented on top of that. The observable behavior seems to indicate this: If you move a file to a different file system, it is removed from the Open Recent list of files, probably because it can no longer be resolved.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...