Skip to content

Instantly share code, notes, and snippets.

@yfrancis
Created October 2, 2012 23:59
Show Gist options
  • Save yfrancis/3824110 to your computer and use it in GitHub Desktop.
Save yfrancis/3824110 to your computer and use it in GitHub Desktop.
NSString *tempDirectoryTemplate =
[NSTemporaryDirectory() stringByAppendingPathComponent:@"myapptempdirectory.XXXXXX"];
const char *tempDirectoryTemplateCString =
[tempDirectoryTemplate fileSystemRepresentation];
char *tempDirectoryNameCString =
(char *)malloc(strlen(tempDirectoryTemplateCString) + 1);
strcpy(tempDirectoryNameCString, tempDirectoryTemplateCString);
char *result = mkdtemp(tempDirectoryNameCString);
if (!result)
{
// handle directory creation failure
}
NSString *tempDirectoryPath =
[[NSFileManager defaultManager]
stringWithFileSystemRepresentation:tempDirectoryNameCString
length:strlen(result)];
free(tempDirectoryNameCString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment