2011-10-19 4 views
4

オブジェクトの配列をplistファイルとしてディスクに保存したい。plistとして保存するオブジェクトを辞書に変換する:プロパティリスト無効な形式

まず、オブジェクトの配列を同等の辞書の配列に変換します。いくつかのプロパティでは問題はありませんが、エラーの一部が問題になります。今私はURLのプロパティのエラーを取得しようとしています。 (コメント行でも問題があるが、私は今、その後に取り組んでいないよ。ここで

はYOEventoクラスのインタフェースである。

#import <MapKit/MapKit.h> 

@interface YOEvento : NSObject 

{ 
    NSURL *url; // <url> 
    NSInteger identificador; // <identificador> 
    NSString *nombre; // stores the <name> tag 
    NSDate *diaDeInicio; // stores the tag <dia-de-inicio> 
    NSDate *diaDeFin; // stores the tag <dia-de-fin> 
    NSString *entradilla; // stores the tag <entradilla> 
    NSURL *foto; // <foto> 
    CLLocationCoordinate2D localizacion; // <localizacion> 
    BOOL isFavourite; 
} 

@property (nonatomic, retain) NSURL *url; 
@property NSInteger identificador; 
@property (nonatomic, retain) NSString *nombre; 
@property (nonatomic, retain) NSDate *diaDeInicio; 
@property (nonatomic, retain) NSDate *diaDeFin; 
@property (nonatomic, retain) NSString *entradilla; 
@property (nonatomic, retain) NSURL *foto; 
@property CLLocationCoordinate2D localizacion; 
@property BOOL isFavourite; 

@end 

 // 1. Convert array of YoEvento in array of Dictionary to be able to save as plist 

    NSMutableArray *tempArray = [NSMutableArray array]; 
    for (YOEvento *evento in self.eventosFavouritesAppDel) { 
     NSDictionary *dict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: 
                    evento.url, 
//                 evento.identificador, 
                    evento.nombre, 
                    evento.diaDeInicio, 
                    evento.diaDeFin, 
                    evento.entradilla, 
//                 evento.foto, 
//                 evento.localizacion, 
                    nil] 
                 forKeys:[NSArray arrayWithObjects: 
                    kURLElement, 
//                 kIdentificadorElement, 
                    kNombreElement, 
                    kDiaDeInicioElement, 
                    kDiaDeFinElement, 
                    kEntradillaElement, 
//                 kFotoElement, 
//                 kLocalizacionElement, 
                    nil]]; 
     [tempArray addObject:dict]; 
    } 
     // 2. Convert the array to NSData 
    NSString *errorDesc; 
    NSData *data = [NSPropertyListSerialization dataFromPropertyList:tempArray format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorDesc]; 

配列を変換するためのコード私が最後にエラーを受け取ったのはエラー "プロパティリストが無効なフォーマット"です。 辞書の内容は有効であるようです。実行時の内容のログは次のとおりです。

すなわち、 NSStringNSDateNSNumberNSArrayNSDictionaryNSData:の
Printing description of dict: 
<CFBasicHash 0x5b99170 [0x1298400]>{type = immutable dict, count = 5, 
entries => 
    0 : <CFString 0xfd00 [0x1298400]>{contents = "entradilla"} = <CFString 0x5b99b10 [0x1298400]>{contents = "Festival Internacional de Cine de Gij\u00f3n M\u00e1s informaci\u00f3n en www.gijonfilmfestival.com "} 
    2 : <CFString 0xfcd0 [0x1298400]>{contents = "nombre"} = <CFString 0x5b99590 [0x1298400]>{contents = "49 FICXix\u00f3n - Festival Internacional de Cine de Gij\u00f3n"} 
    4 : <CFString 0xfcb0 [0x1298400]>{contents = "url"} = <CFURL 0x5b992f0 [0x1298400]>{type = 15, string = http://www.gijon.es/eventos/show/18753-49-ficxixon-festival-internacional-de-cine-de-gijon, encoding = 134217984, base = (null)} 
    5 : <CFString 0xfcf0 [0x1298400]>{contents = "dia-de-fin"} = 2011-11-26 22:59:00 +0000 
    6 : <CFString 0xfce0 [0x1298400]>{contents = "dia-de-inicio"} = 2011-11-18 22:59:00 +0000 
} 

答えて

8

プロパティリストは、クラスの少数のオブジェクトのみを含めることができます。プロパティリストに他のタイプ(NSURLなど)を表示する場合は、最初に許可されたタイプの1つに変換する必要があります。

関連する問題