• 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: Accessing a managedObject property from within an accessor of another property
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessing a managedObject property from within an accessor of another property


  • Subject: Re: Accessing a managedObject property from within an accessor of another property
  • From: Quincey Morris <email@hidden>
  • Date: Tue, 22 Feb 2011 09:44:16 -0800

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@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

  • Follow-Ups:
    • Re: Accessing a managedObject property from within an accessor of another property
      • From: Brad Stone <email@hidden>
References: 
 >Accessing a managedObject property from within an accessor of another property (From: Brad Stone <email@hidden>)

  • Prev by Date: Re: How to detect when an NSTextView has finished being loaded into a window?
  • Next by Date: Reliable way to determine bitness of the kernel
  • Previous by thread: Re: Accessing a managedObject property from within an accessor of another property
  • Next by thread: Re: Accessing a managedObject property from within an accessor of another property
  • Index(es):
    • Date
    • Thread