, "imageTexture.jpg", . "FavoritePhoto.jpg" .
, .
NSError *errorDesc;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *statesDescriptionPath = [documentsDirectory stringByAppendingPathComponent:@"FavoritePhoto.jpg"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *cacheDirectory = [NSFileManager getCacheDirectory];
NSString *temporaryPath = [cacheDirectory stringByAppendingPathComponent:@"imageTexture.jpg"];
NSURL *originalURL = [NSURL fileURLWithPath:statesDescriptionPath];
[fileManager replaceItemAtURL:originalURL withItemAtURL:[NSURL fileURLWithPath:temporaryPath] backupItemName:nil options:NSFileManagerItemReplacementUsingNewMetadataOnly resultingItemURL:&originalURL error:&errorDesc];
if (errorDesc)
{
NSLog(@"there was an error overwriting the favorite photo: %@", errorDesc.description);
}
NSFileManager,
Here is the code for NSFileManager + Powertools.h
#import <Foundation/Foundation.h>
@interface NSFileManager (Powertools)
+ (NSString *)getCacheDirectory;
@end
Here you can see the code for NSFileManager + Powertools.m
#import "NSFileManager+Powertools.h"
@implementation NSFileManager (Powertools)
+ (NSString *)getCacheDirectory
{
NSString *path = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
if ([paths count])
{
NSString *bundleName =
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:bundleName];
}
return path;
}
@end
source
share