Quincey,
Thanks for relying. It's good to have another developer to talk this thru with.
1) customer accessors for isEncrypted didn't work (I have a set exactly like
category)
2) I'm using garbage collection
3) I tried [note isEncrypted] same error
4) i tried using a local ivar i..e Note *thisNote = [self note], no change
I've been trying these variations for days.
On Feb 22, 2011, at 12:44 PM, Quincey Morris wrote:
> On Feb 22, 2011, at 06:19, Brad Stone wrote:
>
>> I've been trying for days to determine why I get EXC_BAD_ACCESS when I try
>> to access a managedObject property from within an accessor of another
>> property?
>>
>> this code in main.m
>> [[self note] setValue:@"HELLO WORLD" forKey:@"category"];
>> NSNumber *tmpVal = [NSNumber numberWithBool:![[[self note]
>> valueForKey:@"isEncrypted"] boolValue]]; // if I type po [self note] I see
>> the note description
>> [[self note] setValue:tmpVal forKey:@"isEncrypted"]; // if I type po [self
>> note] after this I get EXEC_BAD_ACCESS
>>
>> The if statement in the accessor is causing the problem:
>> - (NSString *)category {
>> NSString * tmpValue;
>>
>> [self willAccessValueForKey:@"category"];
>> tmpValue = [self primitiveCategory];
>> [self didAccessValueForKey:@"category"];
>>
>> if ([[self valueForKey:@"isEncrypted"] boolValue]) { // THIS IS CAUSING
>> THE PROBLEM
>> // code to decrypt tmpValue
>> }
>>
>> return tmpValue;
>> }
>
> No answer, but a couple of points:
>
> -- What happens if you write 'note.isEncrypted' (or '[note isEncrypted]')
> instead of '[note valueForKey: @"isEncrypted"]'?
>
> -- What happens if you code your own custom accessors for "isEncrypted", like
> you've done for "category"?
>
> -- EXC_BAD_ACCESS is often a symptom of a memory management problem. Is there
> a problem with the object being returned by '[self note]'? You didn't show
> code for where this is implemented. It's possible that you failed to retain
> the object, or, if you're using garbage collection, returned an object with
> no strong references, or perhaps you returned a zombie object.
>
> What happens in the above code if you set first a local variable to '[[self
> note] retain]' and use the local variable in place of the other references to
> '[self note]'?
>
>
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]