2 // NSURL+SOSPlistWriting.h
5 #import <Security/Security.h>
6 #import <Foundation/NSPropertyList.h>
7 #import <Foundation/NSArray.h>
8 #import <Foundation/NSPropertyList.h>
9 #import <Foundation/NSData.h>
10 #import <Foundation/NSURL.h>
11 #import <Foundation/NSDictionary.h>
12 #import <utilities/debugging.h>
13 #import <utilities/SecFileLocations.h>
15 #if ! __has_feature(objc_arc)
16 #error This file must be compiled with ARC. Either turn on ARC for the project or use -fobjc-arc flag
19 // may want to have this hold incoming events in file as well
21 @implementation NSURL (SOSPlistWriting)
23 - (BOOL)writePlist: (id) plist
26 if (![NSPropertyListSerialization propertyList: plist isValidForFormat: NSPropertyListXMLFormat_v1_0])
28 secerror("can't save PersistentState as XML");
32 NSData *data = [NSPropertyListSerialization dataWithPropertyList: plist
33 format: NSPropertyListXMLFormat_v1_0 options: 0 error: &error];
36 secerror("error serializing PersistentState to xml: %@", error);
40 BOOL writeStatus = [data writeToURL:self options: NSDataWritingAtomic error: &error];
42 secerror("error writing PersistentState to file: %@", error);
50 NSData *data = [NSData dataWithContentsOfURL: self options: 0 error: &error];
53 secdebug("keyregister", "error reading PersistentState from %@: %@", self, error);
57 // Now the deserializing:
59 NSPropertyListFormat format;
60 id plist = [NSPropertyListSerialization propertyListWithData: data
61 options: NSPropertyListMutableContainersAndLeaves format: &format error: &error];
64 secerror("could not deserialize PersistentState from %@: %@", self, error);