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. #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 }

My NSObject class

  #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   

NSObject implementation file

  #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   

Code to store in main data

  - (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]); }}   

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> 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]); }}

This saves the object after every move and does not rewrite it, then starts with a fresh start.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -