Oolite 1.91.0.7646-241128-10e222e
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
28@implementation NSDictionary (OOXMLExtensions)
29
30- (BOOL) writeOOXMLToFile:(NSString *)path atomically:(BOOL)flag errorDescription:(NSString **)outErrorDesc
31{
32 NSData *data = nil;
33 NSString *errorDesc = nil;
34
35 data = [NSPropertyListSerialization dataFromPropertyList:self format:NSPropertyListXMLFormat_v1_0 errorDescription:outErrorDesc];
36 if (data == nil)
37 {
38 if (outErrorDesc != NULL)
39 {
40 *outErrorDesc = [NSString stringWithFormat:@"could not convert property list to XML: %@", errorDesc];
41 }
42#if OOLITE_RELEASE_PLIST_ERROR_STRINGS
43 [errorDesc release];
44#endif
45 return NO;
46 }
47
48 if (![data writeToFile:path atomically:YES])
49 {
50 if (outErrorDesc != NULL)
51 {
52 *outErrorDesc = [NSString stringWithFormat:@"could not write data to %@.", path];
53 }
54 return NO;
55 }
56
57 return YES;
58}
59
60@end
return nil