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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:55:00+00:00 2026-06-04T03:55:00+00:00

I am new to iOS development and could not find a way to solve

  • 0

I am new to iOS development and could not find a way to solve this problem:

I have an app that has two views: one where the user enters some information (say a string), and another view where there is a tableview that includes all the strings that were ever entered (like a history view).

What I am trying to find is a good way to store the input string, then load it into the table view data source once the user switches to the history. I tried to use NSUserdefault but with not much success. Just getting messed up with the data structures, etc.

Here is what I am doing on the main view (where the user enters the input string):

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];     
    NSMutableArray *arr1 = [[NSMutableArray alloc] init];
    arr1 = [defaults arrayForKey:@"historyNames"];

    [arr1 addObject:string];

    [defaults setObject:arr1 forKey:@"historyNames"];    

From some reason I get a warning where I read to arr1, and honestly, I doubt that should work anyway.

Can anyone suggest how I could modify this to work properly and achieve what I am looking for?

Thanks.

  • 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-04T03:55:02+00:00Added an answer on June 4, 2026 at 3:55 am
    [defaults arrayForKey:@"historyNames"];
    

    Will return nil if you never initialized and saved an array for that key in NSUSerDefaults.

    If you initialize and array and set it once (look up how to initialize default values for NSUserDefaults), it will return a proper array.

    Then you can just do

    NSMutableArray *arr1  = [NSMutableArray arrayWithArray:[[defaults arrayForKey@"historyNames"]];
    

    Depending on how many elements this array will have, you may be better off using Core Data. Using user defaults is not very efficient for many/large values, just for small settings and things like that.

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

Sidebar

Related Questions

I am new to ios app development.could you please tell me how to download
I'm fairly new to iOS development, and I'm starting work on an App that
I am quite new to IOS development, so forgive me if this problem turns
I'm new in iOS development, and met this library linking problem in last few
I am completely new to iOS development so I may be doing this wrong
Hello.Am new to ios development.What have to do for NSOpenPanel to work in the
First of all I have to say I am new to iOS development. My
I'm new to Android development, i'm trying to port an IOS app to Android.
I'm quite new here. I have a problem with the new iOS 5.1 slide-in
I'm new to apple's development scene and have been working on an app for

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.