• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Problems with 2 classes HELP
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems with 2 classes HELP


  • Subject: Re: Problems with 2 classes HELP
  • From: Pete Yandell <email@hidden>
  • Date: Sat, 14 Feb 2004 09:30:06 +1100

There are all sorts of things wrong with your code!

On 14/02/2004, at 12:44 AM, Roberto Sobachi wrote:

CollectionList *collection = [[CollectionLists alloc] init];

[collection loadXML];
NSArray *demo = [[NSArray alloc] init];
demo = [collection retrieveArray]; It returns a 0 count NSArray

You've just leaked memory here. You allocate an array and then immediately replace it with another array. You need to go and read the basic memory management docs again.

- (CollectionList *) init
{
[super init];
collection = [[NSMutableArray alloc] init];
return self;
}

You should never init like this. [super init] can return nil, so it should be:

self = [super init];
if (self != nil) {
collection = [[NSMutableArray alloc] init];
}
return self;

You also need a matching dealloc method:

- (void)dealloc
{
[collection release];
}

- (void)loadXML
{

NSString *path = [@"~/Library/Demo/Demo.xml"
stringByExpandingTildeInPath];

collection = [[NSMutableArray arrayWithContentsOfFile: path] retain];

You've just leaked memory again by overwriting your pointer to collection. You need a [connection release] before this line.

NSLog(@"%i", [collection count]); it Returns count Array > 0

This doesn't mean that you got an empty array. You may have failed to load the array entirely and got a nil pointer back. Try NSLog (@"%@", collection) and see what happens.

These are all very basic mistakes. Again, I really strongly recommend that you go and get yourself a book on Cocoa and a good general programming text. You'll learn this stuff a lot quicker that way.

Pete Yandell
http://pete.yandell.com/
_______________________________________________
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.

  • Follow-Ups:
    • Re: Problems with 2 classes HELP
      • From: Dustin Voss <email@hidden>
References: 
 >Problems with 2 classes HELP (From: Roberto Sobachi <email@hidden>)

  • Prev by Date: Re: NSURL - download files
  • Next by Date: Re: static objects "autoreleased with no pool in place - just leaking"
  • Previous by thread: Re: Problems with 2 classes HELP
  • Next by thread: Re: Problems with 2 classes HELP
  • Index(es):
    • Date
    • Thread