for_2012 2013-03-29 08:15 采纳率: 0%
浏览 6095

在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条回答 默认 最新

  • shiter 人工智能领域优质创作者 2015-01-14 14:07
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器