Reputation: 2923
I want to write the method which should create for writing a plist file. I got the example code in the Web but can not understand what is wrong with it. First of all, when I try to call this method - I get a message in log:
2013-03-28 15:33:47.953 ECom[6680:c07] Property list invalid for format: 100 (property lists cannot contain NULL)
2013-03-28 15:33:47.954 ECom[6680:c07] An error has occures <ECOMDataController: 0x714e0d0>
Than why does this line return (null)?
data = [NSPropertyListSerialization dataWithPropertyList:plistData format:NSPropertyListXMLFormat_v1_0 options:nil error:&err];
and the last question - how to remove the warning message for the same line?
Incompatible pointer to integer conversion sending 'void *' to parameter of type 'NSPropertyListWriteOptions' (aka 'insigned int')
h-file
#import <Foundation/Foundation.h>
@interface ECOMDataController : NSObject
{
CFStringRef trees[3];
CFArrayRef treeArray;
CFDataRef xmlValues;
BOOL fileStatus;
CFURLRef fileURL;
SInt32 errNbr;
CFPropertyListRef plist;
CFStringRef errStr;
}
@property(nonatomic, retain) NSMutableDictionary * rootElement;
@property(nonatomic, retain) NSMutableDictionary * continentElement;
@property(nonatomic, strong) NSString * name;
@property(nonatomic, strong) NSString * country;
@property(nonatomic, strong) NSArray * elementList;
@property(nonatomic, strong) id plistData;
@property(nonatomic, strong) NSString * plistPath;
@property(nonatomic, strong) NSData * data;
@property(nonatomic, strong) id filePathObj;
-(void)CreateAppPlist;
@end
m-file
#import "ECOMDataController.h"
@implementation ECOMDataController
@synthesize rootElement, continentElement, country, name, elementList, plistData, data, plistPath;
- (void)CreateAppPlist {
// Get path of data.plist file to be created
plistPath = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"];
// Create the data structure
rootElement = [NSMutableDictionary dictionaryWithCapacity:3];
NSError *err;
name = @"North America";
country = @"United States";
continentElement = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:name, country, nil] forKeys:[NSArray arrayWithObjects:@"Name", @"Country", nil]];
[rootElement setObject:continentElement forKey:@""];
//Create plist file and serialize XML
data = [NSPropertyListSerialization dataWithPropertyList:plistData format:NSPropertyListXMLFormat_v1_0 options:nil error:&err];
if(data)
{
[data writeToFile:plistPath atomically:YES];
} else {
NSLog(@"An error has occures %@", err);
}
NSLog(@"%@ %@ %@", plistPath, rootElement, data);
}
@end
Upvotes: 1
Views: 2433
Reputation: 540075
It seems that you are serializing the wrong element, replace plistData
by rootElement
(and nil
by 0
) in
data = [NSPropertyListSerialization dataWithPropertyList:plistData format:NSPropertyListXMLFormat_v1_0 options:nil error:&err];
Upvotes: 4