NSArray bad access?
NSArray bad access?
- Subject: NSArray bad access?
- From: Philippe Hausler <email@hidden>
- Date: Mon, 17 Jun 2002 02:31:08 -0500
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.