Oolite
Loading...
Searching...
No Matches
OOXMLExtensions.m
Go to the documentation of this file.
1/*
2
3OOXMLExtensions.m
4
5Oolite
6Copyright (C) 2004-2013 Giles C Williams and contributors
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21MA 02110-1301, USA.
22
23*/
24
25#import "OOXMLExtensions.h"
26
27@implementation NSDictionary (OOXMLExtensions)
28
29- (BOOL)writeOOXMLToFile:(NSString*)path atomically:(BOOL)flag errorDescription:(NSString**)outErrorDesc
30{
31 NSData* data = nil;
32 NSString* errorDesc = nil;
33
34 data = [NSPropertyListSerialization dataFromPropertyList:self format:NSPropertyListXMLFormat_v1_0 errorDescription:outErrorDesc];
35 if (data == nil) {
36 if (outErrorDesc != NULL) {
37 *outErrorDesc = [NSString stringWithFormat:@"could not convert property list to XML: %@", errorDesc];
38 }
39#if OOLITE_RELEASE_PLIST_ERROR_STRINGS
40 [errorDesc release];
41#endif
42 return NO;
43 }
44
45 if (![data writeToFile:path atomically:YES]) {
46 if (outErrorDesc != NULL) {
47 *outErrorDesc = [NSString stringWithFormat:@"could not write data to %@.", path];
48 }
49 return NO;
50 }
51
52 return YES;
53}
54
55@end
return nil