Suppose I have a Student class, as shown below:
class Student {
NSNumber *id;
NSString *lastName;
NSString *firstName;
}
Now that I get the records of all students from the web service, I have an NSArray that stores records for all students. At some point, I need to find an array to find a specific student record based on the name.
Suppose I create a dictionary called studentsFirstNameDictionary.
So by adding objects to the students array, I can do
Student objStudent = [[Student alloc] init];
objStudent.Id = someId;
objStudent.firstName = someName;
objStudent.lastName = someLastName;
[studentsDictionary setValue:iterationCounter forKey:objStudent.firstName];
[students addObject:objStudent];
I want to know if it is useful to create this dictionary to speed up the search, as shown below. Also suppose that in any case the array is necessary and for quick searching I create other dictionaries that store the last name and id as keys and indexes as values, as indicated above:
-(Student*)getStudentByFirstName:(NSString *)firstName {
int idxOfStudent = [ studentsDictionary valueForKey:firstName];
return [students idxOfStudent];
}
, , ?
, . , , , ?
P.S.: , , , , , , .