2 for 2012 for_2012 于 2013.03.29 16:15 提问

在ios中创建plist文件出现错误

我想写一个方法用来创建plist文件,在网上搜了一些代码案例,但是不知道哪出错了。在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>

并且为什么这行代码返回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

1个回答

wangyaninglm
wangyaninglm   Ds   Rxr 2015.01.14 22:07
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!