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 6040189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:28:40+00:00 2026-05-23T06:28:40+00:00

I have an application that pulls a list of the top places on flickr

  • 0

I have an application that pulls a list of the top places on flickr and returns the recent photos posted to those places. That is all done dynamically. I am also storing a list of recent images the user has viewed to NSUserDefaults. The data that flickr needs in order to pull up an image is stored in an NSDictionary, so I am writing the NSDictionary to an array, and then storing said array in NSUserDefaults. This is for a learning project, so I’m required to use NSUserDefaults, even if there is likely a better way.

At this point, ALMOST everything works great. However, I am flummoxed on a method of updating the Recent Images after a user views a new image in the dynamic views. NSUserDefaults updates without issue, and the additional recent images show if I shut down the app and restart it.

Here is my code where I write to defaults. Doesn’t seem to be an issue here.

idvc = [[ImageDisplayViewController alloc] init];
idvc.flickrInfo = [placePhotosArray objectAtIndex:[indexPath row]];

// Add data to NSUserDefaults

NSUserDefaults *currentDefaults = [NSUserDefaults standardUserDefaults];
NSData *dataFromRecentArray = [currentDefaults objectForKey:@"recentImages"];

if (dataFromRecentArray != nil)
{
    NSArray *oldArray = [NSKeyedUnarchiver unarchiveObjectWithData:dataFromRecentArray];
    if (oldArray != nil)
    {
        currentRecentImagesArray = [oldArray mutableCopy];
    } else {
        currentRecentImagesArray = [[NSMutableArray alloc] init];
    }
} else {
    currentRecentImagesArray = [[NSMutableArray alloc] init];
}

[currentRecentImagesArray addObject:idvc.flickrInfo];
[[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:currentRecentImagesArray] forKey:@"recentImages"];
[currentRecentImagesArray release];
[self.navigationController pushViewController:idvc animated:YES];
[idvc release];

Here is where I am reading the data back out

- (void)viewWillAppear:(BOOL)animated
{
   [super viewWillAppear:animated];
   NSUserDefaults *currentDefaults = [NSUserDefaults standardUserDefaults];
   NSData *dataFromRecentImages = [currentDefaults objectForKey:@"recentImages"];
   if (dataFromRecentImages != nil) {
    NSArray *currentArray = [NSKeyedUnarchiver unarchiveObjectWithData:dataFromRecentImages];
    recentImagesArray = [[NSArray alloc] initWithArray:currentArray];
   }
}

Honestly, the requirements for the assignment are fulfilled, I could stop here if I wanted to. But I’d like to understand how this is done. I am pretty good at extrapolating generic code examples and applying it to mine, so you don’t have to fix MY specific problem. Just need to know how to update a variable that’s value is set from user defaults after defaults have been updated.

  • 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-23T06:28:40+00:00Added an answer on May 23, 2026 at 6:28 am

    Option 1

    One thing you can do is save to the userDefaults every time a new picture is looked at and then when the “Recent Images” tab is selected, reload from the defaults.

    To make that a little more efficient, you could save an array of newly viewed images, and only save them to the userDefaults when leaving the tab.

    Option 2

    Use add an observer on NSNotificationCenter watching “NSUserDefaultsDidChangeNotification”. That way you can run a function that updates the recent images every time the UserDefaults changes.

    Option 3

    Create your own notification called something like “ImageViewed”. You can register the recent images to listen to that notification from NSNotificationCenter and whenever a new image is viewed, you post that notification to the notification center.

    If you need some clarification on any of those methods, I can try to explain it further.

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

Sidebar

Related Questions

I have an iPad application that pulls in all of its data from an
I have an android application that pulls a list of videos stored in an
We have an n-tier web application that pulls data from SQL Server. Our Data
I have created an application that parses some text files and pulls out and
I'm building a small application that pulls statistics from an API I have no
I have a single page jQuery mobile application that consists of several list views
I have application that makes different queries with different results so the caching in
I have application that is connecting to the DB and if I enter incorrect
I have application that is up more than 3 days. I can see in
I have application that brings response via Ajax and creates 5-20 new jQuery click

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.