views:

47

answers:

2

Reference POST:

http://stackoverflow.com/questions/3681003/core-data-basic-questions

I am able to get the Managed object context from this piece of code. It bring me to another question. I have 2 VIEW CONTROLLERS and 1 NSObject

  1. Userlookup (VC)
  2. UserlookupSettings(VC)
  3. FetchProcessor (NSObject)

In sequence, Userlookup vc loads first and has a button to load the Userlookupsettings VC + a textbox and UiButton. When the app is loaded and I hit the SETTINGS uibutton, things work fine... however, when i do the search (FetchProcessor) and then load the settings, it gives me error (check below please) for


 if (![[managedObject managedObjectContext] save:&error]) {
        NSLog(@"Unresolved error %@, %@, %@", error, [error userInfo],[error localizedDescription]);
        exit(-1);  // Fail  
    }

ERROR:


2010-09-11 03:10:47.148 SAPBasis[975:207] *** -[NSCFString objectID]: unrecognized selector sent to instance 0x3d5d830
2010-09-11 03:10:47.170 SAPBasis[975:207] Serious application error.  Exception was caught during Core Data change processing: *** -[NSCFString objectID]: unrecognized selector sent to instance 0x3d5d830 with userInfo (null)
2010-09-11 03:10:47.170 SAPBasis[975:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString objectID]: unrecognized selector sent to instance 0x3d5d830'

EDITED and added relevant codes..

UserLookup:

-(void) searchUser{
        getUserDetailsService=[[GetUserDetailsSOAPService alloc]init]; // where AbstractServiceProvider *getUserDetailsService; and @interface GetUserDetailsSOAPService : AbstractServiceProvider
        [getUserDetailsService setSettingPreference:settings];
        [settings release];
        [getUserDetailsService setDelegate:self];
        RequestDO * request = [[RequestDO alloc]init];
        request.userID=userIdInputField.text;
        [getUserDetailsService setRequestDO:request];
        [request release];
        NSManagedObjectContext *context = self.referringObject;
        [getUserDetailsService setReferringObject:context];
        [getUserDetailsService execute]; // This is the user search function.
        [getUserDetailsService release];
}

-(void) editUserLookupSettings{
    UserLookupSettings *viewVC = [[UserLookupSettings alloc] initWithNibName:@"UserLookupSettings" bundle:nil];
    viewVC.title =  @"Settings for User Lookup";
    NSManagedObjectContext *context = self.referringObject;
    viewVC.referringObject = context;
    [self.navigationController pushViewController:viewVC animated:YES];
    // Manage memory
    [viewVC release];
}

NOW @implementation GetUserDetailsSOAPService

-(void)execute{
    TCodeSettings *fetch = [[TCodeSettings alloc] init]; // Where @interface TCodeSettings : NSObject <NSFetchedResultsControllerDelegate>
    fetch.referringObject = self.referringObject;
    resultsOfSettings = [fetch initCode]; // Code details given below. I think so is causing the error when this is called.
    [fetch release];
    self.userData = [[NSMutableDictionary alloc] init];
    self.previewData = [[NSMutableArray alloc] init];

    // Creates new Request object and sets its url
    NSString *URLReq = [self.settingPreference getSOAPPrefix];
    URLReq=[URLReq stringByAppendingString:@"Z_USERLOOKUPWS"];
    URLReq=[URLReq stringByAppendingString:[self.settingPreference getSOAPSuffix]];

    theRequest=[NSMutableURLRequest 
                requestWithURL:[NSURL URLWithString:URLReq]
                cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
                timeoutInterval:30.0];

    // Setting specific SOAP headers
    // For SOAP content type is text/xml
    .
    .
    .
    [self makeReqest]; // AbstractServiceProvider we have makeRequest function and it works fine..
}

NOW @interface TCodeSettings : NSObject

- (NSFetchedResultsController *)initCode{
    NSError *error;
    if (![[self fetchedResultsController] performFetch:&error]) {
        // Handle the error
    }else {
        return fetchedResultsController;
    }
}

NOW @interface UserLookupSettings : UITableViewController

- (void)viewDidLoad {   
    NSError *error;
    if (![[self fetchedResultsController] performFetch:&error]) {
        // Handle the error
    }
    [super viewDidLoad];
}

A: 

[getUserDetailsService setDelegate:self];

this could possibly be your bugger but this is not sure until I see at least the headers for all classes involved.

And also, put Logs in all of your Dealloc functions to see if something goes away prematurely.

Cheers

lupu1001
A: 

Your problem here is that at some point, you have swapped out a NSManagedObject for a NSString. When the context goes to save, it sends the objectID message to what it thinks is a managed object but since it is a string object, the string object does not understand the message.

Most likely, the error is actually in a custom NSManagedObject subclass where you assign a relationship. You've set a string instead of managed object.

TechZen
I was reading the documentation at apple dev site and this one question popped into my head. It says that when I do a fetch, a graph is built of that managed object (model) on the managed object context (scratch pad)... if i do 2 fetches of the same table using nsfetchresultscontroller in the same context then then save the first one... will that create a issue?
Accilies
No, the fetches themselves do not alter the graph at all. Any manipulation of the objects in a single context is instantly reflected in the context. You're problem here is that you have a string assigned to a variable that should be a managed object.
TechZen