Robert Warren
Robert Warren

Reputation: 53

Objective-C create dynamic array names based on 1 piece of info in the array or add to that array if it already exists

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];
            }
        }
    }
}

Upvotes: 0

Views: 70

Answers (1)

Chuck
Chuck

Reputation: 237070

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").

Upvotes: 3

Related Questions