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: Steven Burr <email@hidden>
- Date: Sat, 31 Aug 2002 14:12:09 -0700
On Saturday, August 31, 2002, at 01:41 PM, Onar Vikingstad
<email@hidden> wrote:
On lxrdag, aug 31, 2002, at 19:15 Europe/Oslo, Sherm Pendley wrote:
On Saturday, August 31, 2002, at 09:17 AM, Onar Vikingstad wrote:
I am trying to access/get an array from another class, but when I use
[[[AccessControl init] alloc] getAccess] it just returns null.
You've got your alloc: and init: reversed. Alloc creates an object,
and init initializes it - you have to call them in that order, because
if you reverse them, you're trying to initialize an object that
doesn't exist yet.
Try this instead:
[[[AccessControl alloc] init] getAccess];
Won't that result in a memory leak? Presumably the full line will read
something like:
NSArray *a = [[[AccessControl alloc] init] getAccess];
So you'll end up creating an AccessControl object with a retain count
of 1 and no way to release it. I believe either one of these would be
better:
(1)
AccessControl *ac = [[AccessControl alloc] init];
NSArray *a = [ac getAccess];
....
[ac release];
(2)
NSArray *a = [[[[AccessControll alloc] init] autorelease] getAccess];
Ok, that was a typo on my part. But I still get "null" from the array
I'm trying to get. Why is that? In the class I'm getting it from
(AccessControl) the array named access works just fine. And when I use
the getAccess method to return that array, shouldn't it work?
Sorry if this is silly question, but are you perhaps failing to
initialize the array in your init method? Other than that, I can't see
any reason why you would be getting null as the return value.
BTW, by convention, accessors in Cocoa go by the name of the instance
variable to which they provide access. IIRC, methods beginning with
"get" are ordinarily used to read the receiver into a pointer supplied
as an argument. See e.g. the NSString getCharacters:range method.
_______________________________________________
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.