Use of a int type property
Use of a int type property
- Subject: Use of a int type property
- From: Davide Benini <email@hidden>
- Date: Sat, 29 Mar 2008 20:15:36 +0100
In a previous conversation I realised that I can use any tipe as a
property. As a consequence, I decided to use a simple int type for a
"repetitions" property of MyClass, instead of a NSNumber. I changed my
code accordingly, but the changes generated a strange bug. As soon as
I set my int property to a value, any value, the instance of MyClass
becomes unusable. I use the debugger to trace the bug, and realised
that everything is allright, as long as I don't assign a value to
"repetitions". So if I "po" an instance of MyClass I get a
description, until I assign 1 to repetitions; later I can "po
myInstance.key", but if I "po myInstance" i get:
"Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000001
0x92c0d6e4 in objc_msgSend ()
The program being debugged was signaled while in a function called
from GDB.
GDB has restored the context to what it was before the call.
To change this behavior use "set unwindonsignal off"
Evaluation of the expression containing the function
(_NSPrintForDebugger) will be abandoned."
Here is MyClass.h file
@interface MyClass : NSObject {
int repetitions;
NSMutableArray *body; // Il contenuto
NSString *key; // in questo modo posso determinare cambi di chiave!
}
@property int repetitions;
@property (nonatomic, retain) NSMutableArray *body;
@property (nonatomic, retain) NSString *key;
and here the MyClass.m file
#import "MyClass.h"
@implementation DBNMusicBlock
@synthesize body;
@synthesize key;
@synthesize repetitions;
- (void) dealloc
{
[variantEnding release];
[body release];
[super dealloc];
}
- (id) init
{
self = [super init];
if (self != nil) {
body = [[NSMutableArray alloc] init];
repetitions = 1; // if I comment this line, the instance is allright
as long as I don't assign a value to this property
}
return self;
}
What is wrong with this code?
Any idea?
Thanks in advance,
Davide
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden