我有一个错误,如果我将 NSIndexPath 添加到我存储的字典中,它不会存储,NSIndexPath 对象是self.lectureNumber
如果我从我要存储的字典中删除它,它存储得很好。问题可能是什么?
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
};
然后我有一个 chace 类,我将字典存储在
SimpleCache *cache = [[SimpleCache alloc]init];
[cache storeObject:objectToStore withName:self.audiofile inCategory:kFavorites];
简单缓存:
- (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;
}