use dataFromPropertyList for the addition

This commit is contained in:
Mingye Wang 2020-02-26 19:22:19 +08:00
parent ce7ff5709b
commit 6ac9271fbc
2 changed files with 13 additions and 10 deletions

View file

@ -54,12 +54,14 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
NSError * myError = nil;
NSData * dest;
NSDictionary *loc;
loc = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
switch (aFormat)
{
case NSPropertyListJSONFormat:
dest = [NSJSONSerialization dataWithJSONObject:aPropertyList
options:NSJSONWritingPrettyPrinted
error:&myError];
dest = [NSJSONSerialization
dataWithJSONObject:aPropertyList
options:loc != nil ? NSJSONWritingPrettyPrinted : 0
error:&myError];
if (myError != nil && anErrorString != NULL)
{
*anErrorString = [myError description];
@ -67,7 +69,6 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
return dest;
case NSPropertyListObjectiveCFormat:
case NSPropertyListSwiftFormat:
loc = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
dest = [NSMutableData dataWithCapacity:1024];
OAppend(aPropertyList, loc, 0, 2, aFormat, dest);
return dest;

View file

@ -318,15 +318,17 @@ plFormatFromName(NSString *name)
int
dumpToFile(id obj, NSPropertyListFormat fmt, NSString *outfile)
{
NSError * anError;
NSString * errorString = nil;
NSFileHandle *fh;
NSData * outdata = [NSPropertyListSerialization dataWithPropertyList:obj
format:fmt
options:0
error:&anError];
NSData * outdata =
[NSPropertyListSerialization dataFromPropertyList:obj
format:fmt
options:0
errorDescription:&errorString];
if (anError)
{
GSPrintf(stderr, @"Dumping %@ as format %@ - %@\n", obj, fmt, anError);
GSPrintf(stderr, @"Dumping %@ as format %@ - %@\n", obj, fmt,
errorString);
return EXIT_FAILURE;
}