我想编写应该为编写 plist 文件而创建的方法。我在网上得到了示例代码,但不明白它有什么问题。首先,当我尝试调用此方法时 - 我在日志中收到一条消息:
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>
为什么这条线返回(null)?
data = [NSPropertyListSerialization dataWithPropertyList:plistData format:NSPropertyListXMLFormat_v1_0 options:nil error:&err];
最后一个问题 - 如何删除同一行的警告消息?
Incompatible pointer to integer conversion sending 'void *' to parameter of type 'NSPropertyListWriteOptions' (aka 'insigned int')
h文件
#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文件
#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