Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using Protocols (complete message this time...)



On Monday, December 30, 2002, at 09:42 AM, mw wrote:

@interface NPRolloverButton : NSImageView {
NSImage *normalState;
NSImage *overState;
NSImage *downState;
id <NPRolloverProtocol> controller;
SEL downEvent;
}
The controller is not in the nib file at
all. All of the initialization of the custom button is done in its
-awakeFromNib method, which means that the controller object won't be
created yet (since non-nib objects are created after nib-based objects are).
So I want to call alloc and init on 'controller'. This is the first problem.
How the heck do I allocate and initialize a dynamically typed object? I have
no idea what the class is,

who/what does know ? that thing should be passing you the instance.

is it really a controller ? or a delegate ?
a view doesn't usually know of its controller. the controller knows of the view and the model.


and I have tried using things like [controller
class] in the alloc-init statement (formed like [[[controller class] alloc]
init];), but that doesn't work at all. The program still compiles, but I get
a warning that says that -class isn't implemented by the protocol, and then
when that line is executed... nothing happens.

someone who knows better will comment on your usage of protocol in the typing.
i don't think its right. in any case, you should just drop it, it won't give
you that much safety.


A second problem is that whenever I call ANY method on the controller (other
than a method that is part of the protocol, such as -performSelector), the
compiler issues a warning that says that -performSelector isn't part of the
protocol. But since -performSelector is a function of NSObject, it is a
given that all classes will be able to perform -performSelector.

since its just a warning, you can live with it. but ideally you should caste the
object to its real class every time you are messaging it.
but you don't know that i guess.

-felix
_______________________________________________
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: 
 >Using Protocols (complete message this time...) (From: mw <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.