Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / March 2008



Tip: Looking for answers? Try searching our database.

Custom delegate method help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
echosummet@gmail.com - 20 Mar 2008 00:18 GMT
I have a class with a set of 5 variables that are continuously
updated. I have another class with the same variables that needs to be
notified and passed the values of the data in the first class when an
update occurs. Im trying to set up a custom delegate method to do this
but am having some trouble. I saw some examples on developer.apple.com

http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/Comm
unicatingWithObjects/chapter_6_section_4.html#//apple_ref/doc/uid/TP40002974-CH7
-DontLinkElementID_114


where it talks about delegates for a custom class, and also the
example on cocoa dev central that gives a similar scenario.

http://cocoadevcentral.com/articles/000075.php

Would a delegate method be the correct way to implement this? and if
so how would I pass it the values? Both examples I mentioned use a
generic NSObject interface like this:

@interface NSObject (MyObjectDelegateMethod)

- (BOOL)operationShouldProceed;

@end

is this necessary? and what does it do exactly? Thanks for any advice
in advanced!!!
Tom Harrington - 20 Mar 2008 00:54 GMT
In article
<e14ec9de-2626-4667-a2ba-0ced52509f44@e23g2000prf.googlegroups.com>,

> I have a class with a set of 5 variables that are continuously
> updated. I have another class with the same variables that needs to be
[quoted text clipped - 12 lines]
>
> Would a delegate method be the correct way to implement this?

A delegate is one way to do this.  You might also consider using
NSNotification, or key-value observing via
-observeValueForKeyPath:ofObject:change:context:

> and if so how would I pass it the values? Both examples I mentioned
> use a generic NSObject interface like this:
[quoted text clipped - 7 lines]
> is this necessary? and what does it do exactly? Thanks for any advice
> in advanced!!!

That's an informal protocol, so called because objects can choose to
implement the method(s) or not as appropriate.  When you want to call
one of the delegate methods, you first need to check whether the
delegate actually implements it.  The purpose of a declaration like the
one above is to make clear what method signatures you're using and to
keep the compiler happy.

You can also declare a formal protocol (with @protocol), where objects
that adopt the protocol must implement all of the declared methods.

Which is appropriate depends on the situation-- i.e. whether it makes
sense for the delegate objects really need to implement all delegate
methods, or if they only need to implement some of them to be useful.

As for how you pass the values, your delegate methods can take as many
arguments as you need them to take.

Signature

Tom "Tom" Harrington
Independent Mac OS X developer since 2002
http://www.atomicbird.com/

echosummet@gmail.com - 21 Mar 2008 23:02 GMT
On Mar 19, 4:54 pm, Tom Harrington <t...@pcisys.no.spam.dammit.net>
wrote:
> In article
> <e14ec9de-2626-4667-a2ba-0ced52509...@e23g2000prf.googlegroups.com>,
[quoted text clipped - 53 lines]
> Tom "Tom" Harrington
> Independent Mac OS X developer since 2002http://www.atomicbird.com/

Thanks Tom,

I am running with NSNotification and it seems to be doing exactly
whats needed. Thanks again.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.