• 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: -[NSCFString _isMaintainingInverse]: selector not recognized [self = 0x305c]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -[NSCFString _isMaintainingInverse]: selector not recognized [self = 0x305c]


  • Subject: Re: -[NSCFString _isMaintainingInverse]: selector not recognized [self = 0x305c]
  • From: Adam Knight <email@hidden>
  • Date: Fri, 3 Nov 2006 10:06:20 -0600

You get that message when a part of the system expects to see an NSManagedObject and you've passed a string instead. Go through your code and your UI bindings and ensure you're passing a Core Data managed object to that method and not direct user input.

If you absolutely have to use a user-inputted string to lookup an object, I've had success with the following concept to support combo boxes and similar items. Just add code like this to the model object and bind the GUI to the key "detailObjectName" instead of "detailObject":

- (NSString*) detailObjectName
{
return [[self detailObject] valueForKey:@"whateverTheNameKeyIsForYourObject"];
}
- (void) setDetailObjectName: (NSString*) newDetailObjectName
{
NSFetchRequest *fr = [[NSFetchRequest new] autorelease];
[fr setEntity:[NSEntityDescription entityForName:@"Detail" inManagedObjectContext:[self managedObjectContext]]];
[fr setPredicate:[NSPredicate predicateWithFormat:@"whateverTheNameKeyIsForYourObject == %@", value]];
[fr setFetchLimit:1];

NSError *error;
NSArray *results = [[self managedObjectContext] executeFetchRequest:fr error:&error];
if (results != nil) {
if ([results count] == 1) { //We've only asked for one object, so the choices are only 1 or 0 results.
[self setDetailObject:[results objectAtIndex:0]];
} else { //Nothing found; create it and return it
NSManagedObject *detailObject = [NSEntityDescription insertNewObjectForEntityForName:@"Detail" inManagedObjectContext: [self managedObjectContext]];


/** Setup the object here **/
[detail setValue:newDetailObjectName forKey:@"whateverTheNameKeyIsForYourObject"];
// etc.


			[self setDetailObject:detail];
		}
	} else {
		[NSApp presentError:error];
	}
}



--
Adam Knight
codepoetry - http://www.codepoetry.net/products/


On Nov 3, 2006, at 5:33 AM, shaun bear wrote:

I am new to Cocoa programming and CoreData. Can anybody tell me how to add a detail object to a
master-detail relationship without getting the following error:


-[NSCFString _isMaintainingInverse]: selector not recognized [self = 0x305c]


I have 2 custom classes that sub-class NSManagedObject: Master and Detail. I have auto-generated
these classes with accessor using XCode.


There is a -to many relationship from Master to Detail with inverse.

I am using the auto-generated method in "Master" to add the Detail object:

- (void)addDetailObject:(Detail *)value

{
// [[DetailController selectedObjects] objectAtIndex:0];
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];


[self willChangeValueForKey:@"detail" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];

   [[self primitiveValueForKey: @"detail"] addObject: value];

[self didChangeValueForKey:@"detail" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];

    [changedObjects release];
}

I have googled for this but cannot find an example or a solution for how to do this. I did find the cause of the
problem:


"The program is attempting to make the NSArrayController's own proxy object
the contents of the to-many relationship. Data added to the object graph
cannot be proxies for the data to be added but has to be the modeled data
itself. Another way to look at the problem is if the proxies could replace
the data they are supposed to be proxying, they would would no longer be
proxies of data but would have become the data itself."


Any help would be very much appreiciated.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >-[NSCFString _isMaintainingInverse]: selector not recognized [self = 0x305c] (From: shaun bear <email@hidden>)

  • Prev by Date: Re: Copyright Violations using Apple Icons in own Applications?
  • Next by Date: Problems applescripting Core Data subclass
  • Previous by thread: -[NSCFString _isMaintainingInverse]: selector not recognized [self = 0x305c]
  • Next by thread: Odd textView behavior
  • Index(es):
    • Date
    • Thread