Properties? I don't see the connection at all. The instance variables I'm accessing should be available only to the class itself. Otherwise I could just use @public and access it the same way as below, but allowing the function to be defined outside of the implementation.

I want to use an inline function in several places within a certain method in the class, but still have access to instance variables, and do so without passing them in as parameters since the function can call external code which changes their values... it's a long story to explain it thoroughly. :-)

Anyway, if the non-protected access is a known/common/public behavior - great! I wish I knew about this ages ago.


--
Seth Willits



On Apr 21, 2009, at 7:50 PM, Luke the Hiesterman wrote:

It's done all the time. You should read up on Objective-C 2.0 properties, though, to learn when it's best to use properties.

Luke

On Apr 21, 2009, at 7:40 PM, Seth Willits wrote:


Is the non-protected access of instance variables from functions defined inside of @implementations documented anywhere? I'm wondering if this some secret thing that I shouldn't use, or something that's actually pretty common used?



@interface Foo : NSObject
{
        int special;
}

- (void)print;

@end




@implementation Foo

static inline void dotheprint(Foo * self)
{
NSLog(@"%d", self->special); // If defined outside @imp it'd give a compiler error
}

- (id)init;
{
        [super init];
        special = 5;
        return self;
}

- (void)print;
{
        dotheprint(self);
}

@end




--
Seth Willits

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to