Re: How to write a dictionary into an output file
Re: How to write a dictionary into an output file
- Subject: Re: How to write a dictionary into an output file
- From: Julio Bianco <email@hidden>
- Date: Tue, 6 Jun 2006 11:07:45 -0300
Hi,
Thanks for this answer you give my, but I still have some questions
if you are so kind to answer
On Jun 5, 2006, at 6:40 PM, Nick Kreeger wrote:
On 6/5/06, Julio Bianco <email@hidden> wrote:
Hi,
I'm trying to write son dictionary information in a file, and I
realize that I can do it using the method
- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag
and I use it like this:
+(TCLogger *) instance {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSDictionary *LogFile1 = [[NSDictionary alloc]
initWithObjectsAndKeys:
@"one", [NSNumber numberWithInt: 1],
nil];
if ([LogFile1 writeToFile: @"/Users/jbianco/pueba.log"
atomically:
YES])
NSLog(@"escribio el archivo2");
if ([LogFile1 writeToFile: [NSHomeDirectory()
stringByAppendingPathComponent: @"Desktop/log.conf"] atomically: YES])
NSLog(@"escribio el archivo");
[LogFile1 release];
[pool release];
return instance;
}
and when I try to run it, that is not run Ok, because never prints
those logs, and neither creates the file.
Can you tell me what am I doing bad?
Thanks
Julio
_______________________________________________
Could be that your Dictionary initWithObjectsAndKeys: is not
setting up properly. A NSDictionary will not save to file unless it
contains data that can be archived. Your first step should be to
check LogFile1 For instance your code sample looks like it should
write to file, but if you had a special class, let's say a subclass
of NSObject called MyObject. You cannot write MyObject in your
dictionary unless it conforms to the NSCoding protocol.
You tell me this dictionary was not properly set up, then how can I
set it up to be written correctly taking in consideration that I'm
not using any estrange class or object, but a string and an integer
as key an value? I don't know if I need to do something else I am not
performing, because I have exactly that I send you, and it doesn't work.
Also if you are building inside `, you can specify the path as just
@"LogFile.plist" or something and it will write to the directory of
your current build configuration (debug, release, etc.)
Ok, I get it, but there shouldn't be any problem to write this file
in a specific path, using a complete path, is that right?
Thanks for your answers.
Julio
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden