views:

299

answers:

2

hi, i created a new project with a tableview already done by default with the add button which add dates. But the project is im not familiar with the nsmanagedobject thing. I want to add specific string to this not dates. thx for help!!

NSManagedObjectContext *context = [fetchedResultsController managedObjectContext];
NSEntityDescription *entity = [[fetchedResultsController fetchRequest] entity];
NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
[newManagedObject setValue:[NSDate date] forKey:@"timeStamp"];
A: 

Looks like you've started a project using Core-Data. If you don't know what Core-Data is or how to use it, you can find out more here:

http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CoreData/CoreData.pdf

Jasarien
+1  A: 

It sounds like you need to learn about Core Data. I would also recommend Core Data: Apple's API for Persisting Data on Mac OS X by Marcus S. Zarra.

To display a string, rather than a date, you need to modify the data model. The template created a data model with a sigle Event entity that has a data attribute.

You can remove or rename this entity and modify the attributes as desired. You want to add a string attribute.

Then, you will want to specify the name of your new string attribute as the key for sorting in the fetch. You will also want to use it to set the value of the text in the table view cell's text label. Finally, you will need to modify the insert new object method to set a default value for the new attribute.

gerry3
thx!! i have change the attribute to string like you said, in insert new object method i have change [NSDate date] to [NSString string] and thats it and when i open the app it crash any ideas?
There is no `string` method in the NSString class. Try setting the property to a literal objective-C string such as: @"New name"
gerry3
Also, the compiler should have warned you about that method. Do NOT ignore compiler warnings. I recommend modifying the build setting to "treat warnings as errors".
gerry3