Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: request for member in something not a structure or union
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: request for member in something not a structure or union



Thanks for the reply Jens,

So I can't use (id) as the type for my data object, I have to specifically
declare it as a Data*. I thought the point of id's were that you could just
use it whereever you want to refer to an object pointer, and at runtime it
would all get resolved? I guess I haven't fully understood it yet (maybe
thats only for messages?).

I'm now using Data* and it works beautifully thanks. I realized the reason
it wasn't working when I tried declaring the vars as Data* explicitly
before, was because my class properties I was using were not declared as
public. I had thought that those variables should stay private and the
@property keyword created public getter/setters, but it seems I was wrong,
I need to declare the variables as public in addition to the @property
keyword...

And also referring to the variables as data.myVar seemed a bit weird as
well! (seeing as data is a pointer - instead of data->myVar)... but there
you go :P

Cheers,

Memo.


On Wed, 4 Jun 2008 12:32:22 +0200, Jens Ayton <email@hidden>
wrote:
> On Jun 4, 2008, at 11:54, Memo Akten wrote:
>>
>> -(id)setData:(id)d {
>>    self.data = [d retain];  // sidenote: do I need retain here?
>>    int activeIndex = data.activeIndex; // this is where i get the
>> compiler
>> error
>> }
>>
>> I also have a class Data in which I declare:
>> @property (readonly) NSUInteger activeIndex;
>>
>> and so for each instance of a I call [a setData:<instance of data>]
>>
>> As far as I understand this should work should it not? Sorry if this
>> is a
>> basic question but I'm just trying to get to grips with the new
>> syntax and
>> way of working etc...
>>
>> I tried the traditional C method of declaring and passing data as
>> Data*,
>> and then using data->activeIndex but I still get the same error! :S
>
> You need to declare the instance variable as Data *data, then use
> data.activeIndex. Property accesses use dot notation on object
> pointers, but you can only use properties that are known to exist at
> runtime (so you can't use id).
>
> Additionally, the line self.data = [d retain]; is equivalent to [self
> setData:[d retain]], which will cause infinite recursion (unless
> you've declared the data property with a different setter). If you
> want to set the instance variable data, use "self->data" or just
> "data". However, your second access (data.activeIndex) is already
> using the instance variable data, not the property data.
>
> In other words, it's important to keep track of the difference between
> properties (part of the class's interface) and instance variables (an
> implementation detail).
>
>
> --
> Jens Ayton
>
> Today, we celebrate the first glorious anniversary
> of the Information Purification Directives.
>
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Objc-language mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
--
----------------------------
Mehmet S. Akten

email@hidden
www.memo.tv



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >request for member in something not a structure or union (From: Memo Akten <email@hidden>)
 >Re: request for member in something not a structure or union (From: Jens Ayton <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.