Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 03-15-2010, 10:31 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 80
Default best practice: delegate vs NSNotification

hi, i have a dilemma. I have a UIView that is userInteractionEnabled and recieves events from
Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
however, i also have a class that is a Mediator(puremvc, if you know it) that has been assigned this view as its viewComponent. I would like this mediator to know about the touches to the uiview. What is the best way to pass the NSSet and the UIEvent? currently i made a custom protocol of the UIView and had the Mediator conform...but then i started thinking about NSNotifications, etc...any thoughts on this?
vertine is offline   Reply With Quote
Old 03-16-2010, 04:52 AM   #2 (permalink)
Mobile and Web solutions
 
hello24's Avatar
 
Join Date: May 2009
Location: London, UK
Posts: 72
Send a message via Skype™ to hello24
Default

Don't use NSNotification unless your coupling is very loose (or non-existent) or you need to let multiple object know about the event.
hello24 is offline   Reply With Quote
Old 03-16-2010, 05:10 AM   #3 (permalink)
Registered Member
 
macoholic's Avatar
 
Join Date: Dec 2008
Location: around a Mac...in Pune,India :)
Posts: 135
Default

Notifications are generally a brodcast system.
Delegates are helpful in case of tightly coupled components....

On a personal front,When I have a loosly coupled components or I need multiple objects to be notified about an event I use Notifications.

In all other scenarios it's delegates that I love!!

Macoholic
macoholic is offline   Reply With Quote
Old 03-18-2010, 09:29 AM   #4 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Sweden
Age: 32
Posts: 16
Default

Can I send messages to my delegate running on the main thread when running in a separate thread?
MikaelBartlett is offline   Reply With Quote
Old 03-18-2010, 09:58 AM   #5 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,886
Default

Quote:
Originally Posted by MikaelBartlett View Post
Can I send messages to my delegate running on the main thread when running in a separate thread?
Yes you can, by using performSelectorOnMainThread:
harrytheshark is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 258
17 members and 241 guests
14DEV, @sandris, ADY, ArtieFufkin10, bookesp, ckgni, Dani77, DarkAn, HemiMG, iDifferent, jakerocheleau, JasonR, prchn4christ, Rudy, Speed, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:48 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0