尝试在NSUserDefaults中存储nsdictionaries数组时出错

时间:2013-10-12 08:02:11

标签: ios objective-c nsarray nsdictionary nsuserdefaults

基本上我有一系列我想要存储在NSUserDefaults中的NSdictionaries。 pageDict是一个本地NSDictionary LyteData是一个用于存储东西的Singleton类 层次结构来自lyteData.textbookDictArray ---> lyteData.pagesDictArray ---> pageDict(NSDictionary)

    [pageDict setObject:textbookImage forKey:@"image"];
    [pageDict setObject:textbookName forKey:@"name"];
    [pageDict setObject:page forKey:@"page"];
    [pageDict setObject:nameOfClass forKey:@"class"];

    LyteData *lyteData = [LyteData sharedManager];
    [lyteData.pagesDictArray addObject:pageDict];


    [lyteData.textbookDictArray addObject:lyteData.pagesDictArray];
       NSLog(@"array: %@", lyteData.pagesDictArray);
       NSLog(@"textbook array: %@", lyteData.textbookDictArray);

   //THIS CODE IS FOR SAVING THE ARRAY OF TEXTBOOKS AS USERDEFAULT
    [[NSUserDefaults standardUserDefaults]
     setObject:lyteData.textbookDictArray forKey:@"textbookArray"];

我收到此错误:

   Attempt to set a non-property-list object (
        {
        class = hb;
        image = "<UIImage: 0x165c43d0>";
        name = fv;
        page = 25;
    }
) as an NSUserDefaults value for key textbookArray

如何在NSUserDefaults中存储该数组?

1 个答案:

答案 0 :(得分:2)

问题是您尝试将UIImage存储到不支持的NSUserDefaults。有关解决方案,请参阅here