1

I tried to set NSMutableArray as object in NSUserDefault.but it gives following error.

Attempt to set a non-property-list

this is how I tried it.

[[NSUserDefaults standardUserDefaults] setObject:OutboundArray forKey:@"outbound"];
  [[NSUserDefaults standardUserDefaults] synchronize];

NOTE : OutboundArray type is NSMutableArray. What is the wrong with this.I do this inside a method.hope your help.

this is how I assign value to OutboundArray

- (void)assignvaluedForarrays
{
    OutboundArray = nil;
    InboundArray = nil;

    FlightSearchSelected *flightSearch = [FlightSearchSelected new];
    JourneyTy = flightSearch.returnJType;
    DirectRNot = flightSearch.returnNonStoporNot;
    fromAcode = flightSearch.returnFromPort;
    toAcode = flightSearch.returnToPort;

    FlightCnt = FinalDetails.FlightCount;


    OutboundArray = [NSMutableArray array];
    InboundArray = [NSMutableArray array];


    //all round trips
    if ([JourneyTy isEqualToString:@"true"])
    {

            for (int i=0;i<FlightCnt;i++)
            {
                FinalValues *finalValue = testingArray[i];
                NSString *legNumber = finalValue.legnumber;

                if ([legNumber isEqualToString:@"1"])
                {
                    [OutboundArray addObject:testingArray[i]];

                }
                else
                {
                    [InboundArray addObject:testingArray[i]];
                }
            }


    }
    //only one ways trips
    else
    {
        self.finaltableViewbottomLayout.constant = 180;
        for (int i = 0;i<FlightCnt;i++)
        {
            [OutboundArray addObject:testingArray[i]];

        }

    }
}

*testingArray data comes from the previous view controller according to indexpath of the table view.

caldera.sac
  • 4,918
  • 7
  • 37
  • 69
  • Are you sure, OutboundArray is actually an instance of NSMutableArray ? As the error suggests, you're attempting to store an object that is not part of the p-list in NSUserDefaults. A default object must be a property list, that is, an instance of (or for collections a combination of instances of): NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary. If you want to store any other type of object, you should typically archive it to create an instance of NSData. – Robert J. Clegg Mar 01 '16 at 08:15
  • 1
    for OutboundArray I added objects(NSString).yep I tried with NSData also like this http://stackoverflow.com/questions/19720611/attempt-to-set-a-non-property-list-object-as-an-nsuserdefaults.but nothing happened – caldera.sac Mar 01 '16 at 08:21
  • Show us the full code rather than just snippets. Your current code sample works just fine in my test environment. – Robert J. Clegg Mar 01 '16 at 08:22
  • @Tander updated the question – caldera.sac Mar 01 '16 at 08:26

1 Answers1

1

Okay, having a look at your code - the issue is here:

[OutboundArray addObject:testingArray[i]];

My bet is that testingArray contains non-property-list item. So not any of the following instances:

NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary.

If your testingArray has a custom NSObject inside it, this is where your problem is. If that is the case, then you need to archive the array into NSData first, before you store it in NSUserDefaults

Robert J. Clegg
  • 7,231
  • 9
  • 47
  • 99