• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Objective-C & Private functions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective-C & Private functions


  • Subject: Re: Objective-C & Private functions
  • From: Andrew Thompson <email@hidden>
  • Date: Sun, 8 Feb 2004 17:23:10 -0500

On Feb 8, 2004, at 1:59 PM, Peter Fischer wrote:

Hello -
Is there any way to create private "Helper" functions in objective-C? I have not been able to find any information on function scoping within a .h file. Obviously, a function can be declared & implemented in the .m file, making it somewhat private. However, the functions pretty much need to be implemented at the top of the .m file so that other functions can see them. Is there a way to declare private functions in the .h file, or at the very least, forward declare them at the top of a .m file, and provide implementation further down in the .m. Thanks for any help in advance.

--Pete

Assuming you want an Objective C method that's private, and not a C function, the way people usually do this is to use a Category:

In file Foo.m:

@interface Foo (PrivateMethods)
- (void) doSomethingPrivate;
@end

@implementation Foo

- (void) somethingPublic {
[self doSomethingPrivate];
//... etc
}

You can use categories for a bunch of stuff

* amazingly enough, Categorizing your methods, which makes them easier to find in the IDE

* adding methods to other classes, even those you don't have the source to

* simulating things like private methods

They're something you don't see in Java and other similar languages so they're definitely worth taking a few moments to understand.

AndyT (lordpixel - the cat who walks through walls)
A little bigger on the inside

(see you later space cowboy ...)
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Objective-C & Private functions (From: Peter Fischer <email@hidden>)

  • Prev by Date: What can I do with an NSRange in Objective-C?
  • Next by Date: Re: Document App or not?
  • Previous by thread: Re: Objective-C & Private functions
  • Next by thread: Re: Objective-C & Private functions
  • Index(es):
    • Date
    • Thread