Re: Protocol doesn't seem to compile?
Re: Protocol doesn't seem to compile?
- Subject: Re: Protocol doesn't seem to compile?
- From: email@hidden
- Date: Thu, 26 Feb 2004 19:42:42 -0600 (CST)
thank you for your reply, I might not have stated my question very well.
I understand the function of a protocol and how the @protocol keyword is
used, but I was surprised that the compiler doesn't at least check the
syntax of the protocol.. If I make a syntax mistake the compiler ignores
it, unless of course the protocol is referenced by an implementing class.
You have an point that the @protocol contains no code, and by Apple's
documentation, is not a class. This is a good reason that the protocol
isn't compiled, but I find it very odd that the syntax of a declared
protocol is not checked by the compiler unless the protocol has been
implemented, and thus referenced, by a class.
I am writing some libraries that are quite heavy on the abstract side of
things, and who's purpose is to define what in Java would be "Interface"
classes.. I am implementing these with Objective-C using @protocol, but
since the library's purpose is just to define the protocols not implement
them I've found that the compiler doesn't check my syntax at all, but
rather just ignores the protocols.
Any other insights into this?
Thank you for the reply,
Jason
On Feb 26, 2004, at 6:15 PM, Louis C. Sacha wrote:
Hello...
A protocol doesn't contain any code, it only provides a list of methods
that need to be implemented in classes that conform to the protocol.
So for example, if you created the protocol <YourProtocol>
@protocol YourProtocol
- (void)doSomething:(id)sender;
@end
in any class that conforms to the protocol
@interface YourClass: NSObject <YourProtocol>
{...}
...
@end
@implementation YourClass
...
- (void)doSomething:(id)sender
{
NSLog(@"This is what I'm supposed to do.");
}
@end
A different class that conforms to the <YourProtocol> protocol could have
a different implementation. A protocol is just a way of saying that any
class which conforms to the protocol will respond to a particular set of
methods.
Taking a look at the ObjC documentation that Apple provides might help if
you haven't read it already:
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/3objc_language_overview/chapter_3_section_7.html#//apple_ref/doc/uid/20001424/BAJJABHJ
It's also on your hard drive at a similar path in the /Developer folder.
Hope that helps,
Louis
oops! of course i mean @protocol.... up late last night... does anyone
have this problem with @protocol?
Sorry for the mistake!
_______________________________________________
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.
_______________________________________________
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.