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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:39:30+00:00 2026-05-13T13:39:30+00:00

I am new to iphone development. I am old School – I was tought

  • 0

I am new to iphone development. I am “old School” – I was tought to use Procedures etc. when programming. Everything is object oriented these days but my style is still as its always been. Please bear that in mind. My project is tiny and really just a proof of concept.

The program below works on a timer – every 30 seconds it will read a random baby name from my list of names database stored in Dictionary.plist by my app. It then shows this name on the iphone screen.

You can see the full relevant parts of the code below.
What happens is – if I increase the timer to run it very fast – eventually it seems to run out of memory or something as it just shows ???? instead of the next random baby name.
I suspect this is due to me not closing the database file each time I read it.

Anyway, can someone please look at my code (with my above comments into consideration) and tell me what I need to add to stop it showing ???? after so many runs..

I am only opening the file each time in ShowNextName as I couldnt figure out another way to do it..

I know its not great style to use variables at the start of this code that are global etc. but is there maybe a way to restructure or add something to stop it “crashing” or going a bit funny after so many runs…

I’d appreciated that. Thanks.

#import "BabyNameViewController.h"

@implementation BabyNameViewController


NSDictionary *dictionary;
NSString *name;

int nameCount = 0;
int RecordIndex = 0;


- (void)ShowNextname;
{
    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSString *finalPath = [path stringByAppendingPathComponent:@"Dictionary.plist"];
    NSArray* plistArray = [NSArray arrayWithContentsOfFile:finalPath];

    // Generate a random number between 0 and (the number of records-1) - used as a random index!

    RecordIndex=arc4random()%[plistArray count];


    // Select and display currently selected record from the array.
    dictionary = [plistArray objectAtIndex:RecordIndex];
    name = [dictionary objectForKey:@"name"];

    [nameLabelOutlet setText: [NSString stringWithFormat: @"Random Baby Name is: %@", name]];

}   

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

// Initial App entry point - startup code..


// Open the dictionary to count the number of names and store it for later use.
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"Dictionary.plist"];
NSArray* plistArray = [NSArray arrayWithContentsOfFile:finalPath];
nameCount = [plistArray count];

// Generate random name from database   
[self ShowNextname];

// Start up the nameUpdate timer.
[NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(nameUpdate) userInfo:nil repeats:YES];

}

-(void) nameUpdate {
    [self ShowNextname];
}
  • 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-13T13:39:30+00:00Added an answer on May 13, 2026 at 1:39 pm

    The problem may be that every 30 seconds you are reloading the plist into a new array. What you should do is in viewDidLoad load the plist into an instance variable in the object (your view controller class) then just use that instance variable in showNextName. (Also, I’d always name methods starting with a lower case letter and classes with an upper case letter or people might think that ShowNextname is a class instead of a method.)

    Also don’t forget to add [plistArray release]; in your dealloc method.

    Here’s a good free document you might want to read that might help some:

    http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/OOP_ObjC/Introduction/Introduction.html

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

Sidebar

Related Questions

I am fairly new to iphone development and programming in general and am wondering
i am quite new to iphone development but i have been given a old
I am an old developer but new to Objective-C and iPhone development. I am
I am new in iphone development. I want to use parse with Json framework
I am new to iPhone development and want to know which database you use
Im new to iPhone development and I have really taken this to me. I
I'm new to iPhone development, and multiple views (xib or nib) are really confusing
I'm pretty new to iPhone development but I'm close to releasing my first app
I'm new to iPhone development. I'm working on a table view (default UITableView subclass)
I'm new to iPhone development and Xcode, so this might be really obvious. I

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.