Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Problem with objective-c troubleShooting

Hi there,
i'm all new to mac & iOS developement and am getting startet by working throught what appeared to be a great book "Einstieg in Objective-C 2.0 and Cocoa inkl iPhone programming".

what im doing right now is creating an Weblog App for the iPhone by following stepBy step coding and interface instructions by this book.

problem: everything seems to work just fine, i can compile and everything. but one funktion does not work which is creating a new article.

the errorcode looks like that:

+2011-01-25 14:59:28.775 WeblogClientTouch[12682:207] Fehler beim Anlegen eines neuen Artikels+

and is produced by an NSLog:

if (![managedObjectContext save:&error]) {
NSLog(@"Fehler beim Anlegen eines neuen Artikels");
}

so apparently the saving of a new entity 'article' does not work. here some code snippets that might help, first the function that creates a new article in which the error occurs:


- (IBAction)neuerArtikel
{
//erzeuge artikel
NSEntityDescription *artikelDescription = [[fetchedResultsController fetchRequest]entity];
NSManagedObject *newArtikel = [NSEntityDescription insertNewObjectForEntityForName:[artikelDescription name]
inManagedObjectContext:managedObjectContext];

//befĂĽlle artikel mit standardwerten
[newArtikel setValue:NSLocalizedString(@"Neuer Artikel", nil)
forKey:@"titel"];
[newArtikel setValue:[NSDate date] forKey:@"datum"];
[newArtikel setValue:@"Markus" forKey:@"autor"];

//speichere artikel
NSError *error;

if (![managedObjectContext save:&error]) {
NSLog(@"Fehler beim Anlegen eines neuen Artikels");
}

//Tableview aktualisieren
[self.tableView reloadData];
}


in my datamodel i have only one entity named "Artikel" with the attributes: autor, titel, datum, inhalt.


i would be very glad about some tips, because i've been trying to solve the problem for nearly 3 hours now and i dont think it can be that tricky..

Message was edited by: sfluecki

Message was edited by: sfluecki

macbook pro, Mac OS X (10.6.6)

Posted on Jan 25, 2011 6:17 AM

Reply
16 replies

Jan 25, 2011 7:45 AM in response to sfluecki

so i've come a bit further while learning how to use the debugger in Xcode:

<NSManagedObject: 0x60336e0> (entity: Artikel; id: 0x6033750 <x-coredata:///Artikel/tD07EDF16-C361-4D3E-9564-5A0D9426BC052> ; data: {
autor = Markus;
datum = "2011-01-25 15:41:13 +0000";
inhalt = nil;
titel = "Neuer Artikel";


so: my object has been initialised properly, the problem must lie in the task
of saving itself in his container managedObjectContext.

please someone help me.. its now been over 5h of nonstop searching this
one error that keeps me from advancing which is quite frustrating :/

i've programmed before in c++, java and know about the troubles you can
have while programming - but i've never been that frustratedand near to
resigning 🙂

Jan 25, 2011 7:50 AM in response to sfluecki

thx for taking over here, i just changed the NSLog, what came out in gdb is this:


Pending breakpoint 1 - ""ArtikelOverviewController.m":65" resolved
(gdb) step
Current language: auto; currently objective-c
(gdb) step
2011-01-25 16:49:15.031 WeblogClientTouch[15978:207] ErrorInfo Error Domain=NSCocoaErrorDomain Code=1570 "The operation couldn’t be completed. (Cocoa error 1570.)" UserInfo=0x4d5e9e0 {NSValidationErrorObject=<NSManagedObject: 0x60211f0> (entity: Artikel; id: 0x6021260 <x-coredata:///Artikel/tC371BE7F-B7E2-47D8-A75C-21EC1249994D2> ; data: {
autor = Markus;
datum = "2011-01-25 15:49:11 +0000";
inhalt = nil;
titel = "Neuer Artikel";
}), NSValidationErrorKey=inhalt, NSLocalizedDescription=The operation couldn’t be completed. (Cocoa error 1570.)}, {
NSLocalizedDescription = "The operation couldnU2019t be completed. (Cocoa error 1570.)";
NSValidationErrorKey = inhalt;
NSValidationErrorObject = "<NSManagedObject: 0x60211f0> (entity: Artikel; id: 0x6021260 <x-coredata:///Artikel/tC371BE7F-B7E2-47D8-A75C-21EC1249994D2> ; data: { autor = Markus; datum = "2011-01-25 15:49:11 +0000"; inhalt = nil; titel = "Neuer Artikel"; })";
}


seems to be an error with xDataModel, am i right?

Jan 25, 2011 8:13 AM in response to sfluecki

yes.
but if i activate 'optional' with the attributes i get the following SIGBART:


[Session started at 2011-01-25 17:12:22 +0100.]
2011-01-25 17:12:23.019 WeblogClientTouch[16340:207] Unresolved error Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)" UserInfo=0x60420f0 {metadata=<CFBasicHash 0x6041510 [0xff63e0]>{type = immutable dict, count = 7,
entries =>
2 : <CFString 0x60418f0 [0xff63e0]>{contents = "NSStoreModelVersionIdentifiers"} = <CFArray 0x6041cc0 [0xff63e0]>{type = immutable, count = 0, values = ()}
4 : <CFString 0x6041bf0 [0xff63e0]>{contents = "NSPersistenceFrameworkVersion"} = <CFNumber 0x60417c0 [0xff63e0]>{value = +320, type = kCFNumberSInt64Type}
6 : <CFString 0x6041c20 [0xff63e0]>{contents = "NSStoreModelVersionHashes"} = <CFBasicHash 0x6041d50 [0xff63e0]>{type = immutable dict, count = 1,
entries =>
1 : <CFString 0x6041ce0 [0xff63e0]>{contents = "Artikel"} = <CFData 0x6041d00 [0xff63e0]>{length = 32, capacity = 32, bytes = 0x6e935616c5185463f5370ab26eb5f6cf ... 3b2640026f034ca7}
}
7 : <CFString 0xdfd4e4 [0xff63e0]>{contents = "NSStoreUUID"} = <CFString 0x6041a60 [0xff63e0]>{contents = "2C36DD32-3AB0-45A9-A9FF-A8606B64C8EB"}
8 : <CFString 0xdfd354 [0xff63e0]>{contents = "NSStoreType"} = <CFString 0xdfd524 [0xff63e0]>{contents = "SQLite"}
9 : <CFString 0x6041c70 [0xff63e0]>{contents = "NSStoreModelVersionHashesVersion"} = <CFNumber 0x4d22210 [0xff63e0]>{value = +3, type = kCFNumberSInt32Type}
10 : <CFString 0x6041ca0 [0xff63e0]>{contents = "_NSAutoVacuumLevel"} = <CFString 0x6041da0 [0xff63e0]>{contents = "2"}
}
, reason=The model used to open the store is incompatible with the one used to create the store}, {
metadata = {
NSPersistenceFrameworkVersion = 320;
NSStoreModelVersionHashes = {
Artikel = <6e935616 c5185463 f5370ab2 6eb5f6cf 0f97e563 2f305347 3b264002 6f034ca7>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
);
NSStoreType = SQLite;
NSStoreUUID = "2C36DD32-3AB0-45A9-A9FF-A8606B64C8EB";
"_NSAutoVacuumLevel" = 2;
};
reason = "The model used to open the store is incompatible with the one used to create the store";
}

Jan 25, 2011 10:54 AM in response to sfluecki

allRight.
i got it working so far that there's no more errors.

--> i can now klick on 'new article' without any errors, but my tableView does not show the new allocated articles
--> after i restart the app (rebuild, reRun in simulator) the previously added articles are showing in the tableView.

--> somehow my tableView does just update itself whilst starting the app.

in the end of the 'addNewArticle' function i have the following:

[self.tableView reloadData];


the tableView itself is defined by the following:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSArray *sections = [fetchedResultsController sections];
NSUInteger count = 0;
if ([sections count]) {
id <NSFetchedResultsSectionInfo> sectionInfo = [sections objectAtIndex:section];
count = [sectionInfo numberOfObjects];
}
return count;
}


and

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

//Zelle aus dem Cache holen oder erzeugen wenn nicht orhanden
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] autorelease];
}

NSManagedObject *artikel = [fetchedResultsController objectAtIndexPath:indexPath];

//Titel als haupttext der zelle
cell.textLabel.text= [artikel valueForKey:@"titel"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

//Autor und Name als Detailtext der Zelle
NSDateFormatter *dateFormatter = [NSDateFormatter new];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSString *dateString = [dateFormatter stringFromDate:[artikel valueForKey:@"datum"]];
cell.detailTextLabel.text = [NSString stringWithFormat:NSLocalizedString(@"%@ am %@",nil), [artikel valueForKey:@"autor"], dateString];
[dateFormatter release];
return cell;
}


whilst the function fetchedResultsController looks like this.


- (NSFetchedResultsController *)fetchedResultsController
{
if (fetchedResultsController != nil)
return fetchedResultsController;

//FetchRequest initialisieren
NSFetchRequest *fetchedRequest = [NSFetchRequest new];
NSEntityDescription *artikelDescription = [NSEntityDescription entityForName:@"Artikel"
inManagedObjectContext:managedObjectContext];
[fetchedRequest setEntity:artikelDescription];

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]initWithKey:@"datum" ascending:NO];

NSArray *sortDescriptors = [[NSArray alloc]initWithObjects:sortDescriptor, nil];
[fetchedRequest setSortDescriptors:sortDescriptors];

//FetchedResultsController initialisieren
fetchedResultsController = [[NSFetchedResultsController alloc]initWithFetchRequest:fetchedRequest
managedObjectContext:managedObjectContext
sectionNameKeyPath:nil
cacheName:@"Overview" ];
fetchedResultsController.delegate = self;
//aufräumen
[fetchedRequest release];
[sortDescriptor release];
[sortDescriptors release];
return fetchedResultsController;

}




i'm sorry to bother you with that lot of code.. but i'm stuck here since now 8h,
and wouldnt probably be any step further without your help in the first place,
so thanks a lot for the first inputs =)

Jan 25, 2011 11:40 AM in response to sfluecki

hm woudnt 'cellForRowAtIndexPath' take over this part by setting cell.textLabel and cell.accessoryType?
i'm confused ..

its just the reload/update of the tableview that doesnt work, infact the call [tableView reloadData] seems
to not do anything.

did u look at the whole code? its just 2 files and one tableviewcontroller - here the link to a zip of the
whole xcodeproject: http://www.sflueckiger.ch/data/WeblogClientTouch.zip (save)

Problem with objective-c troubleShooting

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.