Re: Mixing Obj-C and C "methods"
Re: Mixing Obj-C and C "methods"
- Subject: Re: Mixing Obj-C and C "methods"
- From: Tom Davie <email@hidden>
- Date: Wed, 07 Aug 2013 09:16:41 +0200
On 30 Jul 2013, at 15:44, Maxthon Chan <email@hidden> wrote:
> My common way of handling this would be NSNotificationCenter. It is a singleton so I am always sure that it is there, and I can wrap all parameters into the userInfo dictionary.
NSNotificationCenter is not a singleton:
> $ cat test.m
> #import <Foundation/Foundation.h>
>
> int main (int argc, char **argv)
> {
> @autoreleasepool
> {
> NSNotificationCenter *a = [[[NSNotificationCenter alloc] init] autorelease];
> NSNotificationCenter *b = [[[NSNotificationCenter alloc] init] autorelease];
> NSLog(@"%p, %p", a, b);
> }
> $ clang -framework Foundation test.m
> $ ./a.out
> 2013-08-07 09:13:25.508 a.out[6155:507] 0x7fcb1040a090, 0x7fcb1040a190
It just happens to have one instance (defaultNotificationCenter) which is common to want to use in lots of locations in your program.
You can not “be sure that [a singleton] is there” any more or less than any other class in your program.
For reference though, both designs for effectively making all objects in your program global objects are pretty horrible for exactly that reason – making everything effectively a global is just terrible design.
Tom Davie
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden