1

plistファイルを書くために作成するメソッドを書きたいです。Web でサンプル コードを入手しましたが、何が問題なのか理解できません。まず、このメソッドを呼び出そうとすると、ログに次のメッセージが表示されます。

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
4

1 に答える 1

4

間違った要素をシリアライズしているplistDataようrootElementです。nil0

data = [NSPropertyListSerialization dataWithPropertyList:plistData format:NSPropertyListXMLFormat_v1_0 options:nil error:&err];
于 2013-03-28T11:50:23.697 に答える