• 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: NSArray bad access?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSArray bad access?


  • Subject: Re: NSArray bad access?
  • From: Esteban <email@hidden>
  • Date: Mon, 17 Jun 2002 00:57:13 -0700

Philippe,
You are forgetting to retain the NSMutableArray you created with the convenience constructor arrayWithObject.

changing the line:
s = [NSMutableArray arrayWithObject:@"test"];
in the implementation of MyObject to:
s = [[NSMutableArray arrayWithObject:@"test"] retain];

should take care of the problem.

-Esteban Uribe

On Monday, June 17, 2002, at 12:31 AM, Philippe Hausler wrote:

ive got an object that on init it creates an array and stores it, then later on ive got a function in that object to grab the count from the array...
heres some code
-------------MyObject.h------------------------------------------------------------------------------------------------------------------------------------------
#import <Foundation/Foundation.h>
@interface MyObject : NSObject {
NSMutableArray *s;
}
- (unsigned)count;
@end
-------------MyObject.m------------------------------------------------------------------------------------------------------------------------------------------
#import "MyObject.h"
@implementation MyObject
- (id)init
{
s = [NSMutableArray arrayWithObject:@"test"];
return self;
}
- (unsigned)count
{
return [s count];
}
@end
-------------MyMainObject.h------------------------------------------------------------------------------------------------------------------------------------------
#import <Cocoa/Cocoa.h>
#import "MyObject.h"
MyObject *o; /*for the real application im going to use this methodology in it has to be here, there is no other way*/
@interface MyMainObject : NSObject
{
}
- (IBAction)countIt:(id)sender;
@end
-------------MyMainObject.m------------------------------------------------------------------------------------------------------------------------------------------
@implementation MyMainObject
- (id)init
{
o = [[MyObject alloc] init];
return self;
}
- (IBAction)countIt:(id)sender
{
printf("%d", [o count]);
}
@end
------------------------------------------------------------------------------------------------------------------------------------------
What am I doing wrong, its more than likely a stupid human error, but the application returns EXC_BAD_ACCESS, implying the variable hasnt been initialized.... but it has in the init of its owning object...
_______________________________________________
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.
_______________________________________________
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.

References: 
 >NSArray bad access? (From: Philippe Hausler <email@hidden>)

  • Prev by Date: Re: NSArray bad access?
  • Next by Date: Re: deleting outline rows using a delegate
  • Previous by thread: Re: NSArray bad access?
  • Next by thread: Re: NSArray bad access?
  • Index(es):
    • Date
    • Thread