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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:39:07+00:00 2026-05-27T10:39:07+00:00

I have looked at numerous posts which state various ways in which to remove

  • 0

I have looked at numerous posts which state various ways in which to remove an object from an array correctly, but I am not sure which method is best to use in my instance. I am loading a dictionary from a plist, this dictionary contains numerous arrays, and these arrays contain another dictionary. So I have 3 storage devices setup, 1 to hold the overall dictionary, another for an array, and finally a dictionary to hold the object from the array:

Header:

NSMutableDictionary *questionsDictionary;
NSMutableArray *questionsArray;
NSDictionary *currentQuestion;

@property (nonatomic, retain) NSMutableDictionary *questionsDictionary;
@property (nonatomic, retain) NSMutableArray *questionsArray;
@property (nonatomic, retain) NSDictionary *currentQuestion;

So my first question is to do with the above, are (nonatomic, retain) the right things to use for the following code.

Next I load in my dictionary from the plist:

.m:

NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"MultipleChoice.plist"];
self.questionsDictionary = [[NSDictionary dictionaryWithContentsOfFile:finalPath] retain];

I then setup my question array based upon type based upon my question type:

- (void)setupQuestionType : (NSString *)qType
{
if ([self.questionsDictionary objectForKey:qType])
{
    self.questionsArray = [self.questionsDictionary objectForKey:qType];

    [self pickRandomQuestion];
}
}

Finally (this is where I get the error), I want to grab the a question at random from this question category:

// Pick a random question number based upon amount of questions
int randomQuestionNum = [[NSNumber numberWithInt:(arc4random() % [self.questionsArray count])] intValue];

// Grab the dictionary entry for that question
currentQuestion = [self.questionsArray objectAtIndex:randomQuestionNum];

// Remove the question from the available questions
[self.questionsArray removeObjectAtIndex:randomQuestionNum]; (Error here)

// Set the question text
self.question.text = [currentQuestion objectForKey:kQuestionkey];

Now if I comment out the removeObjectAtIndex line then the code runs fine, and my question is displayed on the screen. This leads me to believe that it isn’t a null pointer. So the logical answer points to the fact that self.questionsArray isn’t a NSMutableArray. So I tried the following when setting the array:

- (void)setupQuestionType : (NSString *)qType
{
if ([self.questionsDictionary objectForKey:qType])
{
    NSMutableArray *temp = (NSMutableArray *)[self.questionsDictionary objectForKey:qType];
    self.questionsArray = (NSMutableArray *)temp;

    [self pickRandomQuestion];
}
}

Purely to see if I could type_cast it but the error still occurs. Can anyone shed some light on what I’m doing wrong, or the best approach to take?

  • 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-27T10:39:08+00:00Added an answer on May 27, 2026 at 10:39 am

    Don’t typecast NSArray to NSMutableArray. Instead:

    NSArray *temp = [self.questionsDictionary objectForKey:qType];
    self.questionsArray = [NSMutableArray arrayWithArray:temp];
    // code not tested.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've looked through numerous similar questions here at SO, but nothing helps. I have
I have looked everywhere but have not found a problem similar to this. I
I have looked at a lot of answers but have not found a satisfactory
I have looked at the Suggested related questions but none of them are what
I have looked and tried but don't see where I can stop some being
Let me start by saying I have looked at many similar questions asked, but
I have looked on here and found a few examples but nothing works so
Have looked at the answers to similar questions to this, but for the life
I've looked through the numerous posts here on SO and Googled the heck out
I have looked but haven't found a reasonable answer. I have a first TableViewController

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.