class design - Objective-C call private methods -
the following example of private method in objective-c:
myclass.m
#import "myclass.h" @interface myclass (private) -(void) privatemethod:(nsstring *)arg1 and: (nsstring*)arg2; @end @implementation myclass -(void) publicmethod { nslog(@"public method\n"); /*call privatemethod arg1, , arg2 ??? */ } -(void) privatemethod:(nsstring *)arg1 and: (nsstring*)arg2{ nslog(@"arg1 %@ , arg2 %@", arg1, arg2); } @end
i've read private interface / methods declaration. how invoke them other public method ? i've tried [self privatemethod:@"foo" and: @"bar"]
doesn't looks right.
yes, [self privatemethod:@"foo" and:@"bar"]
correct. looks wrong it? , why didn't try it?
(btw, it's not private method, it's hidden interface. outside object knows message signature can still call it. "real" private methods don't exist in objective-c.)
Comments
Post a Comment