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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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, 09:31 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 80
vertine is on a distinguished road
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, 03:52 AM   #2 (permalink)
Mobile and Web solutions
 
hello24's Avatar
 
Join Date: May 2009
Location: London, UK
Posts: 72
hello24 is on a distinguished road
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, 04:10 AM   #3 (permalink)
Registered Member
 
macoholic's Avatar
 
Join Date: Dec 2008
Location: around a Mac...in Pune,India :)
Posts: 137
macoholic is on a distinguished road
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, 08:29 AM   #4 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Sweden
Age: 33
Posts: 17
MikaelBartlett is on a distinguished road
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, 08:58 AM   #5 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
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: 351
7 members and 344 guests
.Snipe, BSH, givensur, guusleijsten, NSString, Paul Slocum, SillyHoney
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,645
Threads: 94,111
Posts: 402,862
Top Poster: BrianSlick (7,990)
Welcome to our newest member, leighec68
Powered by vBadvanced CMPS v3.1.0

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