0
我有一個錯誤,它不會存儲,如果我添加NSIndexPath到字典存儲,NSIndexPath對象是self.lectureNumber
如果我從字典中刪除它我想商店,它存儲得很好。問題是什麼?iOS:NSIndexPath在NSDictionary - 不會存儲到磁盤
NSDictionary *objectToStore = @{
CACHE_KEY_TITLE : self.audioTitle,
CACHE_KEY_AUDIOFILE : self.audiofile,
CACHE_KEY_COLLECTION_NAME : self.collectionName,
CACHE_KEY_DATE_ADDED : [NSDate dateWithTimeIntervalSinceNow:0],
CACHE_KEY_LECTURE_NUMBER : self.lectureNumber,
CACHE_KEY_NUM_LECTURES : self.numLecturesInCollection
};
然後我有一個蔡斯I類存儲在
SimpleCache *cache = [[SimpleCache alloc]init];
[cache storeObject:objectToStore withName:self.audiofile inCategory:kFavorites];
SimpleCache的字典:
- (BOOL)storeObject:(id)object withName: (NSString *)filename inCategory:(StorageType)category
{
NSString *storageFolder = [self getCategoryFor:category];
if (object) {
NSFileManager *fileManager = [[NSFileManager alloc]init];
// Create folder
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:storageFolder];
NSString *dataPathFormated = [dataPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]) {
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:nil];
NSLog(@"Created new directory");
}
NSURL *destinationURL = [[NSURL alloc]initWithString:[NSString stringWithFormat:@"%@/%@",dataPathFormated,filename]];
NSString *destinationString = [NSString stringWithFormat:@"%@/%@",dataPath,filename];
if (![fileManager fileExistsAtPath:[destinationURL path]]) {
if (YES) { // if table view list is shorter than 50
BOOL success = [object writeToFile:destinationString atomically:YES];
//BOOL success2 = [testObject writeToURL:destinationURL atomically:YES encoding:CFStrin error:<#(NSError *__autoreleasing *)#>];
NSLog(@"writing to disk was success?: %d", success);
} else {
}
}
}
return YES;
}