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

  • SEARCH
  • Home
  • 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 924401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:20:51+00:00 2026-05-15T19:20:51+00:00

I have a simple iPhone app which accesses some remote data on start-up then

  • 0

I have a simple iPhone app which accesses some remote data on start-up then asks the user to select one of the options chosen, but this happens each time the app starts, and I want the app to remember that choice for next time around, how can I persist this object using Core Data?

Im very new to Core Data, and I figure its something to do with adding an object to the NSManagedObjectContext but im not sure if there is a way to store one object against a key or something so that I can check if its been chosen before quickly to avoid doing the remote call…

EDIT

Ok, seems like NSUserDefaults is the way to go here, but I have a small issue, my custom class is extends NSManagedObject which I hear is a bit tough to store an instance of in NSUserDefaults, so I wrote a little converter that takes each property of the class and puts it in NSUserDefaults seperatly under different keys.

like so:

-(void)saveDeviceForUser:(Device*) device
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    NSData *encodedActive = [NSKeyedArchiver archivedDataWithRootObject:device.active];
    [defaults setObject:encodedActive forKey:@"UsersDevice_Active"];

    //and so on for each property of the Device object
}

then I retrieve my object in a similar fashion:

-(Device*)loadDeviceForUser
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    NSData *encodedActive = [defaults objectForKey: @"UsersDevice_Active"];
    NSNumber* unarchivedActive = (NSNumber*)[NSKeyedUnarchiver unarchiveObjectWithData: encodedActive];

    Device *d = [[Device alloc] init];
    d.active = unarchivedActive;

    return d;
}

But, when I get to the line above of d.active = unarchivedActive I get an error:

Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[Device setActive:]: unrecognized selector sent to instance 0xac0be10’

My class properties are setup using @dynamic and not @synthesize, so do I have to implement the setters and getters in order for this to work? Will that upset Core Data in any way?

I hope that makes sense

Cheers,
Mark

  • 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-05-15T19:20:52+00:00Added an answer on May 15, 2026 at 7:20 pm

    I would store the object using NSUserDefaults

    When storing a custom object, you must archive it correctly

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

Sidebar

Related Questions

I am using core data in my iPhone app. I have created a simple
I have a very simple Core Data app which pretty much contains strings of
I have very simple iPhone app, which uses just UIButtons , UIlabels , UITableView
I have a universal app which uses simple pLists for data storage and would
i have a simple iPhone app (*.ipa), which downloaded from AppStore. I have changed
I have a content based, read-only iPhone app. Users can select favorite topics, which
I have a fairly simple iPhone app which utilizes CoreData for object persistence. The
I have a very simple iPhone app that requires a random integer from 1-100.
I'm working on a very simple iPhone app, that in the end will have
I have an iPhone app that shows a simple view (View 1) that has

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.