Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9119511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:24:45+00:00 2026-06-17T05:24:45+00:00

Iam trying to save NSMutableDictionary to NSUserDefaults with this code: NSUserDefaults *def = [NSUserDefaults

  • 0

Iam trying to save NSMutableDictionary to NSUserDefaults with this code:

NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
NSMutableDictionary *repositoryData = [[NSMutableDictionary alloc] init];

[repositoryData setObject:personData forKey:@"persondata"];

[def setObject:repositoryData forKey:@"kUserRepository"];
[def synchronize];
[repositoryData removeAllObjects];
[repositoryData release];

But i am getting this msg:

    [NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '{
    persondata = "<Person: 0x1ed57e70>";
}' of class '__NSDictionaryM'.  Note that dictionaries and arrays in property lists must also contain only property values.

and also the Person Class have NSCoding:

Person.h

    @interface Person : NSObject <NSCoding> {
    NSString *name;
    NSString *email;
    NSString *phoneNumber;
    NSString *gender;

    int age;
}

@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *email;
@property (nonatomic, retain) NSString *phoneNumber;
@property (nonatomic, retain) NSString *gender;
@property (assign) int age;


@end

Person.m

    @implementation Person
@synthesize name,email,phoneNumber,age,gender;

#pragma mark
#pragma mark NSCoder

- (void)encodeWithCoder:(NSCoder *)encoder{
    [encoder encodeObject:self.name forKey:@"username"];
    [encoder encodeObject:self.email forKey:@"useremail"];
    [encoder encodeObject:self.phoneNumber forKey:@"userphonenumber"];
    [encoder encodeObject:self.gender forKey:@"usergender"];

    [encoder encodeInt:self.age forKey:@"userage"];
}

- (id)initWithCoder:(NSCoder *)decoder {
    if(self = [super init]){

        self.name = [decoder decodeObjectForKey:@"username"];
        self.email = [decoder decodeObjectForKey:@"useremail"];
        self.phoneNumber = [decoder decodeObjectForKey:@"userphonenumber"];
        self.gender = [decoder decodeObjectForKey:@"usergender"];

        self.age = [decoder decodeIntForKey:@"userage"];
    }
    return self;
}

@end

Any idea why it happen?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:24:46+00:00Added an answer on June 17, 2026 at 5:24 am

    There are very specific restrictions as to what type of data can be synced to NSUserDefaults within an NSDictionary. These include NSString, NSNumber, NSData, NSArray and NSDictionary. Use your NSCoder methods to serialize to NSData (using NSKeyedArchiver) before storing in the NSUserDefaults.

    Also, take a look at this

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in this code iam trying to save text document on server / wwwroot folder.
I am trying to save multiple image using this code. But instead its saving
This is the string I need to post http://www.mysite.com/save?details= {name} Iam trying the following
Iam trying to implement JMS using eclipse.But when I tried to save the code,
I am trying to save a float number which is this long 13.00386644742523 Its
I am trying to save images using the following code: - (void)writeData{ if(cacheFileName==nil) return;
I am trying to save live stream with this example . I am working
Iam trying to figure out whetere data was save to the db in the
I am having trouble saving an NSMutableDictionary. I am trying to save it to
Hello People please find my code below as you can see iam trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.