Class Extensions (Re: Clueless about this warning)
Class Extensions (Re: Clueless about this warning)
- Subject: Class Extensions (Re: Clueless about this warning)
- From: Bill Bumgarner <email@hidden>
- Date: Sat, 04 Oct 2008 10:32:38 -0700
On Oct 4, 2008, at 7:49 AM, Jonathan del Strother wrote:
To avoid those warnings, the method declaration or definition needs to
appear before it's used. Â I usually add a private category at the top
of my .m files where you can declare private methods - something like
this :
@interface BigLetterView ()
- (void)prepareAttributes;
@end
Exactly the correct solution.
But a bit of clarification.
What you have declared is not really a category. It is an extension
to the class BigLetterView.
If you were to change it to:
@interface BigLetterView ()
- (void)prepareAttributes;
- (void)foobarbaz;
@end
The compiler would complain about the lack of the implementation of -
foobarbaz in class BigLetterView.
However, if you had declared the above as a category:
@interface BigLetterView (MySuperSecretSauce)
- (void)prepareAttributes;
- (void)foobarbaz;
@end
The compiler would *not* complain (unless you used '@implementation
BigLetterView (SuperSecretSauce)' to encapsulate the implementation).
That is, class extensions let you privately declare a set of methods
that *must* be implemented in the @implementation for the class. They
are specifically designed to enable the compiler to more retentively
check that you have implemented what you said you would implement.
Class extensions are also the one place where you can redeclare that a
property is readwrite. If you wanted to declare that a property was
publicly readable, but you want it to be readwrite internally, and you
want to take advantage of method (and iVar on Modern ABI) synthesis,
you would:
@interface BigLetterView: NSObject
@property(readonly) NSString *label;
@end
@interface BigLetterView
@property(readwrite) NSString *label;
@end
@implementation BigLetterView
@synthesize label; // synthesizes both -label and -setLabel:
@end
Note that the above assumes modern ABI (64 bit & iPhone Objective-C
2.0 runtimes) and that you are compiling in GC only mode (otherwise,
the compiler will complain that you didn't specify a storage modifier).
b.bum
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden