ios23
ios23

Reputation: 403

-[__NSCFArray bytes]: unrecognized selector sent to instance

I have saved the array of my products in the user default as below:

  NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
  [userDefault setObject:[NSKeyedArchiver archivedDataWithRootObject:plans] forKey:@"plans"];
  [[NSUserDefaults standardUserDefaults] synchronize];

and read the default as below:

    NSArray *plans;
    NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"plans"];
    if (data != nil)
    {
        plans = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    }

But sometimes my app getting crashed with -[__NSCFArray bytes]: unrecognized selector sent to instance while calling unarchiveObjectWithData method.

Upvotes: 1

Views: 221

Answers (1)

pfandrade
pfandrade

Reputation: 2419

At some point you must have stored an NSArray into NSUserDefaults instead of archived data. Have you tried clearing your user defaults and trying again?

Upvotes: 1

Related Questions