Thank you, I think that this is a well known mistake that I forgot.
On 2008-07-22 00:51:57 +0200, Greg Parker <gparker@[EMAIL PROTECTED]
> said:
> FreeMan <basurero@[EMAIL PROTECTED]
> writes:
>> Hello, AFAIK an im****tant purpose of the @[EMAIL PROTECTED]
compiler directive is
to
>> allows for the existence of polimorfic properties where their value is
>> defined in subcl*****. However, I found the issue below which I think
that
>> is inconsistent with this purpose. Specifically in this example, it's
not
>> possible to use a nCols @[EMAIL PROTECTED]
property because its instance variable
is
>> not defined yet in the following Matrix abstract class:
>>
>> #im****t <Foundation/Foundation.h>
>>
>> @[EMAIL PROTECTED]
Matrix : NSOperation {
>> const NSData* elements;
>> }
>> @[EMAIL PROTECTED]
(retain) const NSData* elements;
>> @[EMAIL PROTECTED]
(assign) NSUInteger nRows;
>> @[EMAIL PROTECTED]
(assign) NSUInteger nCols;
>> - (NSInteger)elementAtRow:(NSUInteger)row col:(NSUInteger)col;
>> - (void)dealloc;
>> @[EMAIL PROTECTED]
>>
>> #im****t "Matrix.h"
>>
>> @[EMAIL PROTECTED]
Matrix
>> @[EMAIL PROTECTED]
elements;
>> @[EMAIL PROTECTED]
nRows;
>> @[EMAIL PROTECTED]
nCols;
>> - (NSInteger)elementAtRow:(NSUInteger)row col:(NSUInteger)col {
>> NSInteger* array = (NSInteger*) [elements bytes];
>> // It fails (error: 'nCols' undeclared (first use in this function)
>> //return array[row*nCols+col];
>> // It works
>> return array[row*[self nCols]+col];
>> }
>> - (void)dealloc {
>> if (elements!=nil)
>> [elements release];
>> [super dealloc];
>> }
>> @[EMAIL PROTECTED]
>>
>> In this example the method nCols has been declared in the prototype by
>> menas of the @[EMAIL PROTECTED]
directive (and can be invoked), but has not been
>> implemented in this yet abstract class. HOWEVER, THE DOT SINTAX CANNOT
BE
>> USED. WHY?
>
> Because your code is using the instance variable directly, not the
> property. There's no dot so that's not dot syntax.
>
> These are ivar accesses:
> nCols
> self->nCols
>
> These are property accesses:
> self.nCols
> [self nCols]
>
> In the @[EMAIL PROTECTED]
case there is no ivar, so you get an error. There is
> an ivar in the @[EMAIL PROTECTED]
case as written above, but you generally
> shouldn't use the ivar directly because you're bypassing any atomicity
> and memory-management provided by the property.


|