0

Ok here is a challenge before me I am having trouble with: I need to create multiple arrays in a custom object dynamically heres the idea a student enters their assignments including class name I want to add it to an array dependent on the class name. This is dynamic so i need to create an array of arrays the main array named for the class name. This allows for unlimited number of classes.

I know how to do this with arrays pre named in my object and to load to these array. I am having trouble figuring out the dynamic creation of these array names.

Any ideas I am stuck.

Like I said, just stuck on where to go next so that it can be assigned to an array of ADP1 or ADP2 and if I add an English assignment it load into an array for English and then if I take Calculus I can add that assignment and it will create a new array to load my calculus assignments into.

solved with this:

    for (int i =0; i < [classList.classesArray count]; i++)
{
    NSString *classy = [classList.classesArray objectAtIndex:i];
    NSMutableArray *classless = [classList.classesArray objectAtIndex:i];
    classless = [[NSMutableArray alloc] initWithObjects: nil];

    for (int a =0; a < [assignmentList.assignmentsArray count]; a++)
    {
        if ([educate containsObject:classless])
        {
            if (classy == [[assignmentList.assignmentsArray objectAtIndex:a] classSched])
            {

                Assigned *assignments = [assignmentList.assignmentsArray objectAtIndex:a];
                [classless addObject: assignments];
            }
        }
        else
        {
            [educate addObject:classless];
            if (classy == [[assignmentList.assignmentsArray objectAtIndex:a] classSched])
            {
                Assigned *assignments = [assignmentList.assignmentsArray objectAtIndex:a];
                [classless  addObject: assignments];
            }
        }
    }
}
2
  • what code have you tried to write so far? Commented Apr 8, 2014 at 23:58
  • I am in testing stages of an app. This was a suggestion to improve it. I am running static data into the arrays as it will come from my add assignment screen. As of now I am loading the data into a single array in my custom object. Commented Apr 9, 2014 at 0:27

1 Answer 1

3

It sounds like what you want is an NSDictionary. Arrays don't have names, but dictionaries can have arbitrary keys that correspond to objects, which is basically a "name" for the object (since you can ask the dictionary for an object by "name").

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, it's quite natural in Objective-C to create a "tree" of dictionaries and arrays to contain complex data. It's efficient and easy to do, if you learn a few simple tricks. Much better than creating lots of custom objects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.