Problems using -writeToFile:atomically: from a NSMutableArray
Problems using -writeToFile:atomically: from a NSMutableArray
- Subject: Problems using -writeToFile:atomically: from a NSMutableArray
- From: George Lawrence Storm <email@hidden>
- Date: Fri, 22 Oct 2004 15:59:17 -0700
I need to create a XMLfile from an array of NSDictionaries. I am using the "ToDos" example <http://homepage.mac.com/mmalc/CocoaExamples/controllers.html> as my starting point.
The only changes I have made to that example is to add two methods (shown below) to "MyDocument", placed saveXMLFile: in my first responder chain and call it from my menu.
-----
- (id)sender //IB action to invoke the Save panel.
{
[[NSSavePanel savePanel]
beginSheetForDirectory:NSHomeDirectory() // seems like a reasonable place to start..
file:nil // default filename
modalForWindow:[self windowForSheet] //Run as a sheet, attached to "window"
modalDelegate:self // The save panel should call me when it's done..
didEndSelector:@selector(saveXMLPanelDidEnd:returnCode:contextInfo:) // ... using this selector
contextInfo:NULL];
}
- (void)saveXMLPanelDidEnd:(NSSavePanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
if (returnCode == NSOKButton)
{
NSString *filePath = [sheet filename];
if ((toDos != nil) && ([toDos count] > 0))
{
NSLog(@"%d items in array\n", [toDos count]);
NSEnumerator* enumerator = [toDos objectEnumerator];
id obj = nil;
while (obj = [enumerator nextObject])
NSLog(@"%@", [obj class]);
if (filePath != nil)
{
NSLog(@"File path:%@\n", filePath);
if ([toDos writeToFile:filePath atomically:YES])
{
NSLog(@"Did write");
}
else
{
NSLog(@"Failed to write");
}
}
else
{
NSLog(@"Invalid path");
}
}
else
{
NSLog(@"Invalid array");
}
}
}
-----
My -saveXMLPanelDidEnd: returnCode:contextInfo: fails on the call to [toDos writeToFile:filePath atomically:YES].
I am attempting to write the file to my desktop so I have write privileges and I appear to be feeding it a good path and to my knowledge a good array.
When I try to save as XML I get the following results:
2004-10-22 15:19:39.124 ToDos[705] 2 items in array
2004-10-22 15:19:39.124 ToDos[705] NSCFDictionary
2004-10-22 15:19:39.124 ToDos[705] NSCFDictionary
2004-10-22 15:19:39.124 ToDos[705] File path:/Users/george/Desktop/test3
2004-10-22 15:19:39.124 ToDos[705] Failed to write
-----
Q: What is a NSCFDictionary? I cannot find it on the Apple site or in AppKiDo. I see references to it in the archives but no definition or general documentation on it.
Any hints / what are my next steps?
-----
George Lawrence Storm
Macintosh Applications Development
Snohomish (Seattle), Washington
E-mail: <email@hidden> _______________________________________________
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