Hello I’m trying to set attributes for a viewcontroller nested inside a NSMutableArray,
for example I have 3 ViewController inside this array:
FirstViewController *firstViewController = [FirstViewController alloc];
SecondViewController *secondViewController = [SecondViewController alloc];
ThirdViewController *thirdViewController = [ThirdViewController alloc];
NSMutableArray *viewControllerClasses = [[NSMutableArray alloc] initWithObjects:
firstViewController,
secondViewController,
thirdViewController,
nil];
for (int x=0; x<[viewControllerClasses count]; x++) {
// as an example to set managedObjectContext I otherwise would set firstViewController.managedObjectContext = context;
[viewControllerClasses objectAtIndex:x].managedObjectContext = context;
}
But this results in an error: Request for member “managedObjectContext” in something not a structure or union.
Shouldn’t be “firstViewController” be the same as [viewControllerClasses objectAtIndex:0]?
The
-objectAtIndex:method returns anid, which the dot-syntax cannot be applied on because the compiler can’t determine the getter.Anyway, you should just use fast enumeration (
for/inloop), and you could give a static type so the dot-syntax can be used (assuming FirstViewController and the rest inherits from BaseViewController):Also, you could revert to use brackets:
(and please
-init…immediately after+alloc.)