Quickly access Documents Directory for the iOS Simulator
Let me share a small trick that I use to quickly navigate to documents directory for an iOS application that runs in the simulator. It requires adding some small snippet of code to the app but it really pays off.
Here's the snippet:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if TARGET_OS_SIMULATOR | |
NSString* homeDirectory = [[NSProcessInfo processInfo] environment][@"SIMULATOR_HOST_HOME"]; | |
NSURL *documentsDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; | |
NSString *documentsDirectoryPath = documentsDirectory.path; | |
NSString *simlinkPath = [homeDirectory stringByAppendingFormat:@"/Desktop/SimulatorDocuments"]; | |
unlink(simlinkPath.UTF8String); | |
symlink(documentsDirectoryPath.UTF8String, simlinkPath.UTF8String); | |
#endif |
In essence it creates a symbolic link to app documents directory and puts that symbolic link on your Desktop. Just add it to application: didFinishLaunchingWithOptions:
method and you will find SimulatorDocuments
link recreated on your Desktop anytime you run the app in the simulator.
Looking for an iOS app development company?
case studies
Previous