I create a category for NSDictionary and override couple of methods 1. writeToFile 2. initWithContentsOfFile.
The WriteToFile function works perfectly and my function gets called. The initWithContentsOfFile fails, it doesnt call my extended function and it returns NULL.
Any pointers/solution/guidance what I am missing or doing wrong?
The same thing works for NSString and I am able to call the similar methods.
Update - My Code
#import <Foundation/Foundation.h>
@interface NSDictionary (TESTDictionary)
-(BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile;
-(id)initWithContentsOfFile:(NSString *)path;
@end
The implementation
#import "NSDictionary+TESTDictionary.h"
@implementation NSDictionary (DMPNSDictionary)
-(BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile{
NSData *someData ;
//
//I process somedata and convert the NSDictionary to NSData here
//
//Write the processed data
return [someData writeToFile:path atomically:useAuxiliaryFile];
}
-(id)initWithContentsOfFile:(NSString *)path{
//Read the file to NSData
NSData *someData = [read from the file here];
//convert the NSData to NSDictionary
self = convertedNSDictionary;
return self;
}
@end
And I use them in one of the file as
#import "NSDictionary+TESTDictionary.h"
NSDictionary *xmlDictionary;
//write to file where storepath is in application document directory
[xmlDictionary writeToFile:storePath atomically:YES];
I try reading as follows
NSMutableDictionary *xmlDictionary = [[NSMutableDictionary alloc]initWithContentsOfFile:storePath1];
NSLog(@"Contents ::%@",xmlDictionary);
NSDictionary *xmlDictionary = [[NSDictionary alloc]initWithContentsOfFile:storePath1];
NSLog(@"Contents ::%@",xmlDictionary);
In both the cases I get Contents as null Regards,
Nirav