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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:02:50+00:00 2026-05-24T12:02:50+00:00

I am trying to create a multiple choice test app. I have this code

  • 0

I am trying to create a multiple choice test app. I have this code to read off a .txt file:

filePath = [[NSBundle mainBundle] pathForResource:@"testBank" ofType:@"txt"];
theBank = [[NSString alloc] initWithContentsOfFile:filePath
                                                  encoding:NSUTF8StringEncoding error:NULL];        
multipleChoicePractice = [theBank componentsSeparatedByString:@"\n"];

The multipleChoicePractice NSMutableArray now contains a bunch of NSStrings in this order:

 Question 1
 choice A
 choice B
 choice C
 choice D
 Answer Key
 Rationale
 question ID 1
 [string to id type of question]
 [space 1]
 Question 2
 choice A-2 
 etc etc up to Question 10

I am trying to group each index in groups of 10 so that index 0 to 9 of multipleChoicePractice is index 0 of a new mutable array, questionGroupArary. I tried:

for (i=0; i<=90; i = i+10) { //qArr being a NSMutableArray
            [qArr addObject:[multipleChoicePractice objectAtIndex:i]];
            [qArr addObject:[multipleChoicePractice objectAtIndex:(i+1)]];
            [qArr addObject:[multipleChoicePractice objectAtIndex:(i+2)]];
            [qArr addObject:[multipleChoicePractice objectAtIndex:(i+3)]];
            [qArr addObject:[multipleChoicePractice objectAtIndex:(i+4)]];
            [qArr addObject:[multipleChoicePractice objectAtIndex:(i+5)]];
            [qArr addObject:[multipleChoicePractice objectAtIndex:(i+6)]];
            [qArr addObject:[multipleChoicePractice objectAtIndex:(i+7)]];
            [qArr addObject:[multipleChoicePractice objectAtIndex:(i+8)]];
            [qArr addObject:[multipleChoicePractice objectAtIndex:(i+9)]];

            [questionGroupArray addObject:qArr];
        }

The result of that for loop is that questionGroupArray objectAtIndex: 0 contains EVERYTHING between question 1 and question 10. What is the best way to achieve my goal so that questionGroupArray index 0 contains “question1” to “[space 1]”? I feel like there is a way to do this with a for loop but it escapes me. 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-05-24T12:02:51+00:00Added an answer on May 24, 2026 at 12:02 pm

    A much better way to get a subarray of objects in a consecutive range is to use -[NSArray subarrayWithRange:].

    // Source is your ungrouped array
    NSMutableArray* groups = [NSMutableArray array];
    for (int i = ; i < 90; i += 10) {
        NSArray* sub = [source subarrayWithRange:NSMakeRange(i, 10)];
        [groups addObject:sub];
    }
    // groups is now an array of arrays with your groups.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a multiple choice exam type app. I have the
I'm trying to create a server app in node.js, where multiple clients connect, and
I am trying to create a program that reads multiple choice answers from a
I am trying to create multiple records with two collections that i have View
Trying to create a user account in a test. But getting a Object reference
Trying to create my first iPhone app that would play back audio. When I
Given an XML layout like this, I'm trying to create a XSD schema to
I've been trying to create multiple custom views generating xibs and connecting controllers to
I'm trying to create a simple ajax load test script that dynamically creates divs,
I'm trying to create a custom activity with multiple connectors using WWF 4.0. Could

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.