Re: cocoa-dev digest, Vol 2 #1183 - 18 msgs
Re: cocoa-dev digest, Vol 2 #1183 - 18 msgs
- Subject: Re: cocoa-dev digest, Vol 2 #1183 - 18 msgs
- From: Ondra Cada <email@hidden>
- Date: Sun, 1 Sep 2002 00:21:56 +0200
On Saturday, August 31, 2002, at 11:12 , Steven Burr wrote:
(1)
AccessControl *ac = [[AccessControl alloc] init];
NSArray *a = [ac getAccess];
....
[ac release];
This is wrong too: if getAccess or "...." happen to raise, ac would leak
anyway
(2)
NSArray *a = [[[[AccessControl alloc] init] autorelease] getAccess];
This would be right in a general case. Better would be to implement a
convenience constructor class method though, which does just that
@interface AccessControl:...
+(AccessControl*)accessControl;
...
@end
@implementation AccessControl
+(AccessControl*)accessControl { return [[[self alloc] init] autorelease];
}
...
@end
now, the line in question might look this way:
NSArray *a = [[AccessControl accessControl] getAccess];
*But* I guess it's all wrong here anyway. AccessControl looks like some
kind of controller; if so, it is to be instantiated soon (probably in NIB
loading, at that), and later just accessed:
// first code part, if needed at all (can -- and probably should -- be
replaced by NIB instantiating)
theController=[[AccessControl alloc] init]; // presumed theController is
global or an appropriate outlet
// second code part
[theController whatever]; // "whatever" prepares/fills the array of
something, which is accessed in...
// ...third code part
NSArray *a=[theController getAccess];
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.