• 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: Using Protocols (complete message this time...)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Re: Using Protocols (complete message this time...)
  • From: crucial felix <email@hidden>
  • Date: Mon, 30 Dec 2002 11:37:15 -0500

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>)

  • Prev by Date: Re: multithreading limits?
  • Next by Date: How to do the opposite of global floating window
  • Previous by thread: Using Protocols (complete message this time...)
  • Next by thread: CVS versus OSX cvswrappers
  • Index(es):
    • Date
    • Thread