ios - In Core data unable to store objects -
Here I try to add a list of objects to my array form which try to add that data Has been doing. Features. My NSObject class NSObject implementation file Code to store in main data But only the last value of the array is being stored in the original data, no one can guide me to solve this problem. Thanks in advance. Before you save, you should rewrite the object instead: < pre> This saves the object after every move and does not rewrite it, then starts with a fresh start. #import "ViewController.h" #import "model.h" #import "coredataManager.h" @interface view controller () {NSMutableArray * entries; } @end @ Implementation View Controller - (zero) viewDidoad {entries = [[NSMUTABARARROL] INST]; coredataManager * coreobj = [[coredataManager alloc] init]; Model * obj = [[Model alloc] initWithContents: @ "1" alternate link: @ "1" DownloadURL: @ "1"]; Model * obj2 = [[Model alloc] initWithContents: @ "2" Alternate link: @ "2" DownloadURL: @ "2"]; Model * obj3 = [[Model alloc] initWithContents: @ "3" Alternate link: @ "3" DownloadURL: @ "3"]; [To add entries: obj]; [To add entries: obj2]; [Add Entries: obj3]; NSLog (@ "% @", entries); [Corobe's Store Value: Entries]; [Super viewedload]; // Setup an additional after loading the view, usually from any nib }
#import & lt; Foundation / Foundation.h & gt; @ Interface model: NSObject @property (copy) NSString * filename; @property (copy) NSString * Alternatively; @property (copy) NSString * downloadurl; - (id) initWithContents: (NSString *) Fname Alternative Links: (NSString *) Download Link: (NSString *) DURL; @end
#import "model.h" @ implementation model @ synthesis downloadurl, filename, alternatively; - (id) initWithContents: (NSString *) Fname alternateLink: (NSString *) Download URL: (NSString *) DURL {if ((self = [super init])) {downloadurl = [DURL copy]; File name = [copy fname]; Alternatelink = [Elycol Copy]; } Healthy return; } @end
- (zero) store price: (NSMutableArray *) sample {sample * value = [ NSEntityDescription insertNewObjectForEntityForName: Managed object contexts in @ "sample": self. Managed Object Contex]; For (int i = 0; i & lt; sample.count; i ++) {model * obj = [sample item: endx: i]; value.url = obj.downloadurl; Value.filename = obj.filename; value. Alternative = obj.alternatelink; } NSError * error; If (! [Managed Object Contact Contact: & amp; Error]) {NSLog (@ "Ohops, Could not Save:% @", [Error Localized Description]); }}
sample * value; {Value = [NSEntityDescription insertNewObjectForEntityForName: @ Managed Object Contains in "Sample": self.managedObjectContext]; (for int i = 0; i & lt; sample.count; i ++); Model * obj = [sample objectAtIndex: i]; value.url = obj.downloadurl; Value.filename = obj.filename; value. Alternative = obj.alternatelink; NSError * error; If (! [Managed Object Contact Contact: & amp; Error]) {NSLog (@ "Ohops, Could not Save:% @", [Error Localized Description]); }}
Comments
Post a Comment