0

In the interface (.h) of the viewController:

@property (strong, nonatomic) NSMutableArray* myMutableArray;

calculate method is as:

- (void) calculate {

    DataObject* pObj = [DataObject objStart:(dataStart) objEnd:(dataEnd) objDay:(day)];

    [myMutableArray addObject:pObj];

}

I receive this error message:

Use of undeclared identifier 'myMutableArray': did you mean '_myMutableArray' ?

4

2 回答 2

1

If you do not have the property synthesized manually (@synthesize myMutableArray;) the compiler will create an iVar with an underscore prefix (which is the same as @synthesize myMutableArray = _myMutableArray);

To access it use

[_myMutableArray addObject:pObj];

or

[self.myMutableArray addObject:pObj];

If you have it synthesized manually like this

@synthesize myMutableArray = nameOfMyBackingIVar

you can access your NSMutableArray this way:

[nameOfMyBackingIVar addObject:pObj];
于 2012-11-27T13:24:34.763 回答
1

You are using XCode4 :)

Here you are not required to @synthesize. Compiler creates all ivars itself as _ivarName. i.e.,

@synthesize myMutableArray=_myMutableArray;

If you want to override it then you can as

@synthesize myMutableArray; 

or, in this way

@synthesize myMutableArray=myMutableArray;
于 2012-11-27T13:44:48.113 回答