|Apr 13, 2008, 12:36 PM||#1|
Is there any similiar to a private method in Objective-C?
I want to just write a simple helper method, but I don't want to expose it to the public interface (since that breaks encapsulation and what not).
Does Objective-C support anything like this?
Like if I write this
NSString *s = [self helper:txtFirst.text];
s = [self helper:txtLast.text];
Obviously, I'll get a compile error if I haven't declared "helper" in the header file. Is there any way around this?
|Apr 13, 2008, 12:40 PM||#2|
Just declare helper: in the .m file before @implementation, like so:
@interface YourClass (PrivateMethods) - (NSString *)helper:(NSString *)arg; @end
|Apr 13, 2008, 01:16 PM||#5|
Note that unlike Java this doesn't actually prevent other objects accessing these methods. You'll get the normal warning about methods not existing when you compile, but it'll work at runtime.
|Apr 13, 2008, 02:05 PM||#6|
But, for the sake of most development, the distinction of public/private isn't to actually protect code, but act as enforcement for good code policy, and help make it clear what can and shouldn't be used in APIs. Categories are sufficient for this purpose.
iMac 2013 27", 13" 2012 rMBP, iPad Air, iPhone 6
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|Objective-C Method Calls counter||TheHeavySoldier||Mac Programming||4||Mar 12, 2014 07:47 AM|
|example objective c code||arkmannj||iPhone/iPad Programming||2||Jul 26, 2013 10:05 PM|
|Class Method -> Function -> Instance Method?||Blakeasd||Mac Programming||11||Jun 19, 2013 02:53 AM|
|Objective-C noob: EXC_BAD_ACCESS with simple print method?||dancks||Mac Programming||14||Apr 27, 2013 04:47 PM|
|Imac program similiar to power point?||Vell843||Mac Applications and Mac App Store||2||Aug 20, 2012 12:42 PM|
All times are GMT -5. The time now is 10:20 PM.