Why NSDictionary writeToFile fails if keys are NSDate objects
Hi,
I am trying to use writeToFile from NSDictionary and I cannot get it working. I have made the following test:
NSDate *key = [[NSDate alloc] init];
NSArray *test = [[NSArray alloc] initWithObjects:@"Easy", key, nil];
[test writeToFile:[self dataFilePath] atomically:YES];
Which perfectly works and returns YES
But if I do:
NSDate *key = [[NSDate alloc]init];
NSArray *test = [[NSArray alloc] initWithObjects:@"Easy",key, nil];
NSDictionary *testDict = [[NSDictionary alloc] initWithObjectsAndKeys:test,key,nil];
[testDict writeToFile:[self dataFilePath] atomically:YES];
It fails. Why is that? Why is I use a NSDate as a key it fails writing into a file but I can work with this Dictionary in everything else?
The following code works:
NSDate *key = [[NSDate alloc]init];
NSArray *test = [[NSArray alloc] initWithObjects:@"Easy",key, nil];
NSDictionary *testDict = [[NSDictionary alloc] initWithObjectsAndKeys:test,@"Value1",key,"@Value2",nil];
[testDict writeToFile:[self dataFilePath] atomically:YES];
Thanks in advance
I am trying to use writeToFile from NSDictionary and I cannot get it working. I have made the following test:
NSDate *key = [[NSDate alloc] init];
NSArray *test = [[NSArray alloc] initWithObjects:@"Easy", key, nil];
[test writeToFile:[self dataFilePath] atomically:YES];
Which perfectly works and returns YES
But if I do:
NSDate *key = [[NSDate alloc]init];
NSArray *test = [[NSArray alloc] initWithObjects:@"Easy",key, nil];
NSDictionary *testDict = [[NSDictionary alloc] initWithObjectsAndKeys:test,key,nil];
[testDict writeToFile:[self dataFilePath] atomically:YES];
It fails. Why is that? Why is I use a NSDate as a key it fails writing into a file but I can work with this Dictionary in everything else?
The following code works:
NSDate *key = [[NSDate alloc]init];
NSArray *test = [[NSArray alloc] initWithObjects:@"Easy",key, nil];
NSDictionary *testDict = [[NSDictionary alloc] initWithObjectsAndKeys:test,@"Value1",key,"@Value2",nil];
[testDict writeToFile:[self dataFilePath] atomically:YES];
Thanks in advance
Mac Mini