[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

patch for NSApplication.m

From: David Relson
Subject: patch for NSApplication.m
Date: Wed, 24 Jul 2002 14:47:53 -0400


In looking at NSApplication.m, I noticed class method "sharedInstance". I was pleased to see the Gang of Four's singleton pattern in use :-)

However, it bothers me to see an object assigned to global variable NSApp before the object is initialized. Changing the code slightly would initialize the object before it's assigned.

Also, to be consistent with the singleton pattern, method -[NSApplication init] should _not_ assign a value to NSApp. All usages of NSApp in this method should be changed.

Below is a patch that corrects both of these issues.


--- Source/NSApplication.m.orig Wed Jul 24 11:53:57 2002
+++ Source/NSApplication.m      Wed Jul 24 14:14:54 2002
@@ -489,8 +489,7 @@
        * problems with some classes' initialization code that tries
        * to get the shared application.
-      NSApp = [self alloc];
-      [NSApp init];
+      NSApp = [[self alloc] init];
   return NSApp;
@@ -513,8 +512,7 @@
     CREATE_AUTORELEASE_POOL (_app_init_pool);

     self = [super init];
-    NSApp = self;
-    if (NSApp == nil)
+    if (self == nil)
              (@"Cannot allocate the application instance!\n", nil));

David Relson                   Osage Software Systems, Inc.
address@hidden       Ann Arbor, MI 48103
www.osagesoftware.com          tel:  734.821.8800

reply via email to

[Prev in Thread] Current Thread [Next in Thread]