RE: where have all the IVARS gone? (long time passing...)
RE: where have all the IVARS gone? (long time passing...)
- Subject: RE: where have all the IVARS gone? (long time passing...)
- From: Vinay Prabhu <email@hidden>
- Date: Mon, 10 Jul 2006 11:23:12 +0530
- Importance: Normal
The '< >' symbols I have used to point the class name,
the actual code looks like this,
@interface myClass (Private)
//Private variables
int iVar1;
float iVar2;
//Private methods
- (void)doSomething;
@end
This works perfectly fine, because I have used the same approach to hide the
private variables in a static library created by me. Where I need to expose
the .h file.
The static library is up and used in other application without any problems.
Successfully hiding the private variables.
-----Original Message-----
From: Rob Ross [mailto:email@hidden]
Sent: Friday, July 07, 2006 11:44 PM
To: Vinay Prabhu
Cc: email@hidden
Subject: Re: where have all the IVARS gone? (long time passing...)
On Jul 7, 2006, at 9:29 AM, Vinay Prabhu wrote:
> you can have the instance variables hidden in the implementation
> file (i.e,
> .m files),
>
> using the header
> @interface <class name> (Private)
> iVars...
> @end
>
> Read the Objective C basics, it is available in
> apple web site
>
I'm pretty sure that doesn't work. Like Bill Bumgarner wrote, you're
defining a category here (and I'm assuming the '< >' symbols you used
don't really mean you wanted a Protocol) and categories don't have
instance variables, only method declarations.
But even if you meant:
@implementation Foo
int myInt;
...
@end
That only creates a Global variable scoped to the .m file, in effect
a Class variable, not an instance variable. When I first started with
Obj-C I tried all manner of ways of having hidden instance variables
but as far as I know the best you can do is to define the instance
variable as @private in the @interface section; it will have private
scope but still be visible in the interface declaration. (And I
understand the Obj-C runtime allows other classes access to even the
private variables via appropriate methods, so nothing is *truly*
private. I guess I'm on the honor system!
Rob
>
> -----Original Message-----
> From: cocoa-dev-bounces+vinayprabhu=email@hidden
> [mailto:cocoa-dev-bounces
> +vinayprabhu=email@hidden]On
> Behalf Of Rob Ross
> Sent: Friday, July 07, 2006 12:33 PM
> To: email@hidden
> Subject: where have all the IVARS gone? (long time passing...)
>
>
> I'm new to Cocoa & Objective-C, and I've been randomly going through
> the header files in the Foundation framework just to get a feel for
> how Objective-C header files are written, and I've noticed that there
> seem to be no instance variables declared anywhere.
>
> I understand the concept of encapsulation; I'm not looking for
> instance variables to use them, but rather to see how "real"
> Objective-C classes are designed. So how do classes like NSString,
> NSSet or NSValue manage their internal state? Like Michael Palin once
> said (or would have, had he been a developer)
>
> "You wouldn't get very far in life if your class instances have no
> internal state."
>
> Is there some secret way of having instance variables and not
> declaring them in the interface files?
>
>
> Rob Ross
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> 40tataelxsi.co.
> in
>
> This email sent to email@hidden
>
> The information contained in this electronic message and any
> attachments to this message are intended for the exclusive use of
> the addressee(s)and may contain confidential or privileged
> information. If you are not the intended recipient, please notify
> the sender or email@hidden
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s)and may contain confidential or privileged information. If you are not the intended recipient, please notify the sender or email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden