Search Results

Search found 215 results on 9 pages for 'coredata'.

Page 3/9 | < Previous Page | 1 2 3 4 5 6 7 8 9  | Next Page >

  • objectWithFieldNAme Best Practice for CoreData

    - by Rafael
    Hello, I'm trying to implements some methods for my CoreData models and I'm wonndering if the way I'm doing it is a good practice. I want to implement methods of the type getObjectsWithFieldName. This methods could be used by severals views. So the way I'm doing it is implementing a Class method in the model in the following way: +(NSArray *)getObjectWithFieldName:(NSString *)fieldName andContext:(NSManagedObjectContext *) context; Is this a good practice? Or there is another way to do it for iPhone Development? Thanks in advanced.

    Read the article

  • iOS 5 - Coredata Sqlite DB losing data after killing app

    - by Brian Boyle
    I'm using coredata with a sqlite DB to persist data in my app. However, each time I kill my app I lose any data that was saved in the DB. I'm pretty sure its because the .sqlite file for my DB is just being replaced by a fresh one each time my app starts, but I can't seem to find any code that will just use the existing one thats there. It would be great if anyone could point me towards some code that could handle this for me. Cheers B - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (__persistentStoreCoordinator != nil) { return __persistentStoreCoordinator; } NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"FlickrCoreData.sqlite"]; NSError *error = nil; __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } return __persistentStoreCoordinator; }

    Read the article

  • CoreData could not fulfill a fault when adding new attribute

    - by cagreen
    I am receiving a "CoreData could not fulfill a fault for ..." error message when trying to access a new attribute in a new data model. If I work with new data I'm ok, but when I attempt to read existing data I get the error. Do I need to handle the entity differently myself if the attribute isn't in my original data? I was under the impression that Core Data could handle this for me. My new attribute is marked as optional with a default value. I have created a new .xcdatamodel (and set it to be the current version) and updated my NSPersistentStoreCoordinator initialization to take advantage of the lightweight migration as follows: NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; NSError *error = nil; persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } Any help is appreciated.

    Read the article

  • iPhone app store approval - coredata design change

    - by satyam
    I created an app, uploaded to app store and approved by app store as well. Its ready for download. The app is based on coredata. Now I changed the design of the app to add new functionality. Changes include addition of new attributes to current entities, deletion of few entities etc. Now, if I upload the app to app store, does it approve or not? Do I have to put and Note saying that "Please uninstall old version and install new version?" Will my app be approved first of all or not.

    Read the article

  • Save object in CoreData

    - by John
    I am using CoreData with iPhone SDK. I am making a notes app. I have a table with note objects displayed from my model. When a button is pressed I want to save the text in the textview to the object being edited. How do I do this? I've been trying several things but none seem to work. Thanks EDIT: NSManagedObjectContext *context = [fetchedResultsController managedObjectContext]; NSEntityDescription *entity = [[fetchedResultsController fetchRequest] entity]; NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context]; [newManagedObject setValue:detailViewController.textView.text forKey:@"noteText"]; NSError *error; if (![context save:&error]) { /* Replace this implementation with code to handle the error appropriately. abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button. */ NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } The above code saves it correctly but it saves it as a new object. I want it to be saved as the one I have selected in my tableView.

    Read the article

  • Big trouble after app update. CoreData migration error

    - by MrBr
    this morning we had a big trouble with our iphone app. We had to even take it off the store. The thing is that we made real small changes to our xcdatamodel. We thought that the update process is automatically taking care about exchanging it the right way until we found out something like CoreData migration exists. We are using the UIManagedDocument to connect to the persistent store. How is it possible to exchange this file with the new one? While we were developing we just uninstalled the whole app from the device and then installed it again and everything worked. How can we simulate this process in the app store with updates? UPDATE I try to set the migration option like this _database = [[UIIManagedDocument alloc] init]; NSMutableDictionary *options = [[NSMutableDictionary alloc] init]; [options setObject:[NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresAutomaticallyOption], _database.persistentStoreOptions = options; but the app is still crashing with ** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation.'

    Read the article

  • NSData in CoreData is not saving properly

    - by abisson
    I am currently trying to store images I download from the web into an NSManagedObject class so that I don't have to redownload it every single time the application is opened. I currently have these two classes. Plant.h @property (nonatomic, retain) NSString * name; @property (nonatomic, retain) PlantPicture *picture; PlantPicture.h @property (nonatomic, retain) NSString * bucketName; @property (nonatomic, retain) NSString * creationDate; @property (nonatomic, retain) NSData * pictureData; @property (nonatomic, retain) NSString * slug; @property (nonatomic, retain) NSString * urlWithBucket; Now I do the following: - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { PlantCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath]; Plant *plant = [self.fetchedResultsController objectAtIndexPath:indexPath]; cell.plantLabel.text = plant.name; if(plant.picture.pictureData == nil) { NSLog(@"Downloading"); NSMutableString *pictureUrl = [[NSMutableString alloc]initWithString:amazonS3BaseURL]; [pictureUrl appendString:plant.picture.urlWithBucket]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:pictureUrl]]; AFImageRequestOperation *imageOperation = [AFImageRequestOperation imageRequestOperationWithRequest:request success:^(UIImage *image) { cell.plantImageView.image = image; plant.picture.pictureData = [[NSData alloc]initWithData:UIImageJPEGRepresentation(image, 1.0)]; NSError *error = nil; if (![_managedObjectContext save:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); } }]; [imageOperation start]; } else { NSLog(@"Already"); cell.plantImageView.image = [UIImage imageWithData:plant.picture.pictureData]; } NSLog(@"%@", plant.name); return cell; } The plant information is present, as well as the picture object. However, the NSData itself is NEVER saved throughout the application opening and closing. I always have to REDOWNLOAD the image! Any ideas!? [Very new to CoreData... sorry if it is easy!] thanks!

    Read the article

  • Detailstext in TableView from Coredata Iphone

    - by user554867
    Hey, that is my first question here at stackoverflow. Let me try to be specific as I can. The project is as follows: I am trying to parse an xml file in an iphone app, which works already. I am saving the parsed data into the CoreData of the Iphone. So far so good: I have two elements of the xml file which I want to show in the tableview as the text and the detailtext. Now the strange behaviour occurs: If I take the data of the Core Data and trying to visualize them in the tableview, then both elements are displayed in seperate cells and not as detailtext of the element. If I am just taking a constant string for the detailtext, then it works, but if I am trying to take for every cell a specific element from the Core Data then it is shown seperately in the tableview. I googled a lot, reading here and there. I dont know which code I should show because I dont have a clue where exactly the mistake could be. Maybe someone can answer that immediately because it is a stupid mistake somewhere, which is common. Thanks for your help.

    Read the article

  • Problem while adding new Object to CoreData App

    - by elementsense
    Hi Another Day, another CoreData problem,...but hopefully the last one now. Ok here is a copy of what I have : I have a List of Hotel Guests that stay in one Room and have Preferences. Once ready the user should select a guest and see the data and should also be able to add new guest, select the room (maintained also by application) and select their preferences (where the user can also add new preferences). The guest can have no or many preferences. So here is what I have so far. I created 3 Entities : - Rooms with roomnumber - Preferences with name - GuestInfo with name - with these Relationships room (Destination Rooms) and prefs (Destination Preferences with "To-Many Relationship") The prefs is a NSSet when you create a Managed Object Class. Now I created a UITableViewController to display all the data. I also have an edit and add mode. When I add a new Guest and just fill out the name, everything works fine. But when I want to add the prefs or the room number I get this error : Illegal attempt to establish a relationship 'room' between objects in different contexts Now, what confuses me is that when I add a guest and enter just the name, save it, go back and edit it and select the prefs and room number it works ? I have this line in both ViewControllers to select the room or prefs : [editedObject setValue:selectedRoom forKey:editedFieldKey]; with this .h : NSManagedObject *editedObject; NSString *editedFieldKey; NSString *editedFieldName; Again, it works on the editing mode but not when I want to add a fresh object. And to be sure, this is what I do for adding an new Guest : - (IBAction)addNewItem { AddViewController *addViewController = [[AddViewController alloc] initWithStyle:UITableViewStyleGrouped]; addViewController.delegate = self; addViewController.context = _context; // Create a new managed object context for the new book -- set its persistent store coordinator to the same as that from the fetched results controller's context. NSManagedObjectContext *addingContext = [[NSManagedObjectContext alloc] init]; self.addingManagedObjectContext = addingContext; [addingContext release]; [addingManagedObjectContext setPersistentStoreCoordinator:[[_fetchedResultsController managedObjectContext] persistentStoreCoordinator]]; GuestInfo *info = (GuestInfo *)[NSEntityDescription insertNewObjectForEntityForName:@"GuestInfo" inManagedObjectContext:addingContext]; addViewController.info = info; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:addViewController]; [self.navigationController presentModalViewController:navController animated:YES]; [addViewController release]; [navController release]; } Anything I have to do to initialize the Room or Prefs ? Hope someone can help me out. Thanks

    Read the article

  • populate CoreData data model from JSON files prior to app start

    - by johannes_d
    I am creating an iPad App that displays data I got from an API in JSON format. My Core Data model has several entities(Countries, Events, Talks, ...). For each entity I have one .json file that contains all instances of the entity and its attributes as well as its relationships. I would like to populate my Core Data data model with these entities before the start of the App (otherwise it takes about 15 minutes for the iPad to create all the instances of the entities from the several JSON files using factory methods). I am currently importing the data into CoreData like this: -(void)fetchDataIntoDocument:(UIManagedDocument *)document { dispatch_queue_t dataQ = dispatch_queue_create("Data import", NULL); dispatch_async(dataQ, ^{ //Fetching data from application bundle NSURL *tedxgroupsurl = [[NSBundle mainBundle] URLForResource:@"contries" withExtension:@"json"]; NSURL *tedxeventsurl = [[NSBundle mainBundle] URLForResource:@"events" withExtension:@"json"]; //converting the JSON files to NSDictionaries NSError *error = nil; NSDictionary *countries = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfURL:countriesurl] options:kNilOptions error:&error]; countries = [countries objectForKey:@"countries"]; NSDictionary *events = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfURL:eventsurl] options:kNilOptions error:&error]; events = [events objectForKey:@"events"]; //creating entities using factory methods in NSManagedObject Subclasses (Country / Event) [document.managedObjectContext performBlock:^{ NSLog(@"creating countries"); for (NSDictionary *country in countries) { [Country countryWithCountryInfo:country inManagedObjectContext:document.managedObjectContext]; //creating Country entities } NSLog(@"creating events"); for (NSDictionary *event in events) { [Event eventWithEventInfo:event inManagedObjectContext:document.managedObjectContext]; // creating Event entities } NSLog(@"done creating, saving document"); [document saveToURL:document.fileURL forSaveOperation:UIDocumentSaveForOverwriting completionHandler:NULL]; }]; }); dispatch_release(dataQ); } This combines the different JSON files into one UIManagedDocument which i can then perform fetchRequests on to populate tableViews, mapView, etc. I'm looking for a way to create this document outside my application & add it to the mainBundle. Then I could copy it once to the apps DocumentsDirectory and be able I use it (instead of creating the Document within the app from the original JSON files). Any help is appreciated!

    Read the article

  • Bulk update & occasional insert (coredata) - Too slow

    - by Andrew
    Update: Currently looking into NSSET's minusSet links: http://stackoverflow.com/questions/1475636/comparing-two-arrays Hi guys, Could benefit from your wisdom here.. I'm using Coredata in my app, on first launch I download a data file and insert over 500 objects (each with 60 attributes) - fast, no problem. Each subsequent launch I download an updated version of the file, from which I need to update all existing objects' attributes (except maybe 5 attributes) and create new ones for items which have been added to the downloaded file. So, first launch I get 500 objects.. say a week later my file now contains 507 items.. I create two arrays, one for existing and one for downloaded. NSArray *peopleArrayDownloaded = [CoreDataHelper getObjectsFromContext:@"person" :@"person_id" :YES :managedObjectContextPeopleTemp]; NSArray *peopleArrayExisting = [CoreDataHelper getObjectsFromContext:@"person" :@"person_id" :YES :managedObjectContextPeople]; If the count of each array is equal then I just do this: NSUInteger index = 0; if ([peopleArrayExisting count] == [peopleArrayDownloaded count]) { NSLog(@"Number of people downloaded is same as the number of people existing"); for (person *existingPerson in peopleArrayExisting) { person *tempPerson = [peopleArrayDownloaded objectAtIndex:index]; // NSLog(@"Updating id: %@ with id: %@",existingPerson.person_id,tempPerson.person_id); // I have 60 attributes which I to update on each object, is there a quicker way other than overwriting existing? index++; } } else { NSLog(@"Number of people downloaded is different to number of players existing"); So now comes the slow part. I end up using this (which is tooooo slow): NSLog(@"Need people added to the league"); for (person *tempPerson in peopeArrayDownloaded) { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"person_id = %@",tempPerson.person_id]; // NSLog(@"Searching for existing person, person_id: %@",existingPerson.person_id); NSArray *filteredArray = [peopleArrayExisting filteredArrayUsingPredicate:predicate]; if ([filteredArray count] == 0) { NSLog(@"Couldn't find an existing person in the downloaded file. Adding.."); person *newPerson = [NSEntityDescription insertNewObjectForEntityForName:@"person" inManagedObjectContext:managedObjectContextPeople]; Is there a way to generate a new array of index items referring to the additional items in my downloaded file? Incidentally, on my tableViews I'm using NSFetchedResultsController so updating attributes will call [cell setNeedsDisplay]; .. about 60 times per cell, not a good thing and it can crash the app. Thanks for reading :)

    Read the article

  • best way to store list of websites on iphone app

    - by Jonathan
    By best I mean most efficient. So don't go on about subjectiveness. I have a list of websites and I want to store the list on the iphone locally, there must be an URL, title and a small image (like 32x32 max image size). I don't think I should be using CoreData for this. Should I be using a plist?

    Read the article

  • CoreData, transient atribute and EXC_BAD_ACCESS.

    - by Lukasz
    I'm trying to build simple file browser and i'm stuck. I defined classes, build window, add controllers, views.. Everything works but only ONE time. Selecting again Folder in NSTableView or trying to get data from Folder.files causing silent EXC_BAD_ACCESS (code=13, address0x0) from main. Info about files i keep outside of CoreData, in simple class, I don't want to save them: #import <Foundation/Foundation.h> @interface TPDrawersFileInfo : NSObject @property (nonatomic, retain) NSString * filename; @property (nonatomic, retain) NSString * extension; @property (nonatomic, retain) NSDate * creation; @property (nonatomic, retain) NSDate * modified; @property (nonatomic, retain) NSNumber * isFile; @property (nonatomic, retain) NSNumber * size; @property (nonatomic, retain) NSNumber * label; +(TPDrawersFileInfo *) initWithURL: (NSURL *) url; @end @implementation TPDrawersFileInfo +(TPDrawersFileInfo *) initWithURL: (NSURL *) url { TPDrawersFileInfo * new = [[TPDrawersFileInfo alloc] init]; if (new!=nil) { NSFileManager * fileManager = [NSFileManager defaultManager]; NSError * error; NSDictionary * infoDict = [fileManager attributesOfItemAtPath: [url path] error:&error]; id labelValue = nil; [url getResourceValue:&labelValue forKey:NSURLLabelNumberKey error:&error]; new.label = labelValue; new.size = [infoDict objectForKey: @"NSFileSize"]; new.modified = [infoDict objectForKey: @"NSFileModificationDate"]; new.creation = [infoDict objectForKey: @"NSFileCreationDate"]; new.isFile = [NSNumber numberWithBool:[[infoDict objectForKey:@"NSFileType"] isEqualToString:@"NSFileTypeRegular"]]; new.extension = [url pathExtension]; new.filename = [[url lastPathComponent] stringByDeletingPathExtension]; } return new; } Next I have class Folder, which is NSManagesObject subclass // Managed Object class to keep info about folder content @interface Folder : NSManagedObject { NSArray * _files; } @property (nonatomic, retain) NSArray * files; // Array with TPDrawersFileInfo objects @property (nonatomic, retain) NSString * url; // url of folder -(void) reload; //if url changed, load file info again. @end @implementation Folder @synthesize files = _files; @dynamic url; -(void)awakeFromInsert { [self addObserver:self forKeyPath:@"url" options:NSKeyValueObservingOptionNew context:@"url"]; } -(void)awakeFromFetch { [self addObserver:self forKeyPath:@"url" options:NSKeyValueObservingOptionNew context:@"url"]; } -(void)prepareForDeletion { [self removeObserver:self forKeyPath:@"url"]; } -(void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if (context == @"url") { [self reload]; } } -(void) reload { NSMutableArray * result = [NSMutableArray array]; NSError * error = nil; NSFileManager * fileManager = [NSFileManager defaultManager]; NSString * percented = [self.url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSArray * listDir = [fileManager contentsOfDirectoryAtURL: [NSURL URLWithString: percented] includingPropertiesForKeys: [NSArray arrayWithObject: NSURLCreationDateKey ] options:NSDirectoryEnumerationSkipsHiddenFiles error:&error]; if (error!=nil) {NSLog(@"Error <%@> reading <%@> content", error, self.url);} for (id fileURL in listDir) { TPDrawersFileInfo * fi = [TPDrawersFileInfo initWithURL:fileURL]; [result addObject: fi]; } _files = [NSArray arrayWithArray:result]; } @end In app delegate i defined @interface TPAppDelegate : NSObject <NSApplicationDelegate> { IBOutlet NSArrayController * foldersController; Folder * currentFolder; } - (IBAction)chooseDirectory:(id)sender; // choose folder and - (Folder * ) getFolderObjectForPath: path { //gives Folder object if already exist or nil if not ..... } - (IBAction)chooseDirectory:(id)sender { //Opens panel, asking for url NSOpenPanel * panel = [NSOpenPanel openPanel]; [panel setCanChooseDirectories:YES]; [panel setCanChooseFiles:NO]; [panel setMessage:@"Choose folder to show:"]; NSURL * currentDirectory; if ([panel runModal] == NSOKButton) { currentDirectory = [[panel URLs] objectAtIndex:0]; } Folder * folderObject = [self getFolderObjectForPath:[currentDirectory path]]; if (folderObject) { //if exist: currentFolder = folderObject; } else { // create new one Folder * newFolder = [NSEntityDescription insertNewObjectForEntityForName:@"Folder" inManagedObjectContext:self.managedObjectContext]; [newFolder setValue:[currentDirectory path] forKey:@"url"]; [foldersController addObject:newFolder]; currentFolder = newFolder; } [foldersController setSelectedObjects:[NSArray arrayWithObject:currentFolder]]; } Please help ;)

    Read the article

  • iPhone - Core Data crash on migration

    - by Sergey Zenchenko
    I have problems, when i install app from Xcode all works but if I build app and install it from iTunes I have an error with the database at launch. This happens only than i have changes in the core data model and need to migrate to a new version. At first launch at crashes with message: Thread 0: 0 libSystem.B.dylib 0x00034588 pwrite + 20 1 libsqlite3.dylib 0x000505ec _sqlite3_purgeEligiblePagerCacheMemory + 2808 2 libsqlite3.dylib 0x000243d8 sqlite3_backup_init + 7712 3 libsqlite3.dylib 0x000244ac sqlite3_backup_init + 7924 4 libsqlite3.dylib 0x0000d418 sqlite3_file_control + 4028 5 libsqlite3.dylib 0x000228b4 sqlite3_backup_init + 764 6 libsqlite3.dylib 0x00022dd0 sqlite3_backup_init + 2072 7 libsqlite3.dylib 0x000249a8 sqlite3_backup_init + 9200 8 libsqlite3.dylib 0x00029800 sqlite3_open16 + 11360 9 libsqlite3.dylib 0x0002a200 sqlite3_open16 + 13920 10 libsqlite3.dylib 0x0002ab84 sqlite3_open16 + 16356 11 libsqlite3.dylib 0x00049418 sqlite3_prepare16 + 54056 12 libsqlite3.dylib 0x00002940 sqlite3_step + 44 13 CoreData 0x00011958 _execute + 44 14 CoreData 0x000113e0 -[NSSQLiteConnection execute] + 696 15 CoreData 0x000994be -[NSSQLConnection prepareAndExecuteSQLStatement:] + 26 16 CoreData 0x000be14c -[_NSSQLiteStoreMigrator performMigration:] + 244 17 CoreData 0x000b6c60 -[NSSQLiteInPlaceMigrationManager migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:] + 1040 18 CoreData 0x000aceb0 -[NSStoreMigrationPolicy(InternalMethods) migrateStoreAtURL:toURL:storeType:options:withManager:error:] + 92 19 CoreData 0x000ad6f0 -[NSStoreMigrationPolicy migrateStoreAtURL:withManager:metadata:options:error:] + 72 20 CoreData 0x000ac9ee -[NSStoreMigrationPolicy(InternalMethods) _gatherDataAndPerformMigration:] + 880 21 CoreData 0x0000965c -[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:] + 1328 At next launches app doesn't loads data from database.

    Read the article

  • How to assign optional attribute of NSManagedObject in a NSManagedObjectModel having Three NSManaged

    - by Kundan
    I am using coredata framework. In my NSManagedObjectModel i am using three entities that are Class, Student and Score where class and student have one-to-many & inverse relationship and Student and Score have also inverse but one-one relationship. Score entity has all optional attributes and having default '0' decimalVaue, which is not assigned at the time new Student is added. But later i want to assign them score individually and also to particular attribute not all of score attributes in a go. I am able to create and add Students to particular Class but dont have any idea how to call particular student and assign them score. For example I want to assign Score'attribute "dribbling" [there are many attributes like "tackling"] a decimal value to Student "David" of Class "Soccer" ,how i can do that? Thanks in advance for any suggestion.

    Read the article

  • How to later assign value to optional attribute of NSManagedObject in a NSManagedObjectModel having

    - by Kundan
    I am using coredata framework. In my NSManagedObjectModel i am using three entities that are Class, Student and Score where class and student have one-to-many & inverse relationship and Student and Score have also inverse but one-one relationship. Score entity has all optional attributes and having default '0' decimalVaue, which is not assigned at the time new Student is added. But later i want to assign them score individually and also to particular attribute not all of score attributes in a go. I am able to create and add Students to particular Class but dont have any idea how to call particular student and assign them score. For example I want to assign Score'attribute "dribbling" [there are many attributes like "tackling"] a decimal value to Student "David" of Class "Soccer" ,how i can do that? Thanks in advance for any suggestion.

    Read the article

  • Ideas for loading initial data in an iPhone application?

    - by Derek Clarkson
    Hi all, In my app I want to load some initial data to show the user how it works. The app uses a CoreData managed sqllite db. SO far I've thought of 3 options: Write code into a class to programmatically create the data. Create a xml file in the apps resources and load through a NSXmlParser whose delegate creates the entries in the sqllite db. Same as option #2, but use a json file and bring in a 3rd party lib to read it. Are there other options I have not found yet? and given that I'm talking about perhaps 6 records per table when there are 3 tables, which would you choose?

    Read the article

  • Problems with CoreDataBooks Example from Apple

    - by eemceebee
    Hi I am currently playing with CoreData and have a problem with the CoreDataBooks Example from Apple. Basically I just wanted to extend the data model. I updated the model class aswell and no compiler error, butr a crash when I want to start the example. Unresolved error Error Domain=NSCocoaErrorDomain Code=134130 UserInfo=0x1316ce0 "Operation could not be completed. (Cocoa error 134130.)", { URL = file://localhost/.../CoreDataBooks.sqlite; ...some nonsense info ... reason = "Can't find model for source store"; } Do I need to updat the sqlite database ? Thanks

    Read the article

  • How to fetch managed objects sorted by calculated value

    - by Marcin Zbijowski
    Hello, I'm working on the app that uses CoreData. There is location entity that holds latitude and longitude values. I'd like to fetch those entities sorted by distance to the user's location. I tried to set sort descriptor to distance formula sqrt ((x1 - x2)^2 + (y1 - y2)^2) but it fails with exception "... keypath ... not found in entity". NSString *distanceFormula = [NSString stringWithFormat:@"sqrt(((latitude - %f) * (latitude - %f)) + ((longitude - %f) * (longitude - %f)))", location.coordinate.latitude, location.coordinate.latitude, location.coordinate.longitude, location.coordinate.longitude]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:distanceFormula ascending:YES]; [fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]]; NSError *error; NSArray *result = [[self managedObjectContext] executeFetchRequest:fetchRequest error:&error]; I'd like to fetch already sorted objects rather then fetch them all and then sort in the code. Any tips appreciated.

    Read the article

  • migrate/ update core data app without erasing user data!

    - by treasure
    hello, i have a very complicated problem that i would like to share with you and maybe someone can answer it for me. before i start i have to say that i am very new in this. So, i have a coredata iphone app (much like the recipes app) that uses a pre-populated sql database. The user can add/edit his own data but the default data cannot be deleted. the useres data are ALL saved in the same sql database. QUESTION: what do i have to do in order to: - update some (not all) of the default data that are stored in the sql database without "touching" the user's data? (the model will stay the same - no new entities etc-) (if the user uninstall the app and then reinstall the new version everything will be ok but i dont want to do this, obviously). can someone PLEASE help in coding level?

    Read the article

  • applicationWillTerminate Appears to be Inconsistent

    - by Lauren Quantrell
    This one has me batty. In applicationWillTerminate I am doing two things: saving some settings to the app settings plist file and updating any changed data to the SQLite database referenced in the managedObjectContext. Problem is it works sometimes and not others. Same issue in the simulator and on the device. If I hit the home button while the app is running, I can only sometimes get the data to store in the plist and into the CoreData store. It seems that it's both works or neither works, and it makes no difference if I switch the execution order (saveState, managedObjectContext or managedObjectContext, saveState). I can't figure out how this can happen. Any help is greatly appreciated. lq AppDelegate.m @synthesize rootViewController; - (void)applicationWillTerminate:(UIApplication *)application { [rootViewController saveState]; NSError *error; if (managedObjectContext != nil) { if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) { // Handle error exit(-1); // Fail } } } RootViewController.m - (void)saveState { NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; [userDefaults setInteger:self.someInteger forKey:kSomeNumber]; [userDefaults setObject:self.someArray forKey:kSomeArray]; }

    Read the article

  • Can get members, but not count of NSMutableArray

    - by Curyous
    I'm filling an NSMutableArray from a CoreData call. I can get the first object, but when I try to get the count, the app crashes with Program received signal: “EXC_BAD_ACCESS”. How can I get the count? Here's the relevant code - I've put a comment on the line where it crashes. - (void)viewDidLoad { [super viewDidLoad]; managedObjectContext = [[MySingleton sharedInstance] managedObjectContext]; if (managedObjectContext != nil) { charactersRequest = [[NSFetchRequest alloc] init]; charactersEntity = [NSEntityDescription entityForName:@"Character" inManagedObjectContext:managedObjectContext]; [charactersEntity retain]; [charactersRequest setEntity:charactersEntity]; [charactersRequest retain]; NSError *error; characters = [[managedObjectContext executeFetchRequest:charactersRequest error:&error] mutableCopy]; if (characters == nil) { NSLog(@"Did not get results for characters: %@", error.localizedDescription); } else { [characters retain]; NSLog(@"Found some character(s)."); Character* character = (Character *)[characters objectAtIndex:0]; NSLog(@"Name of first one: %@", character.name); NSLog(@"Found %@ character(s).", characters.count); // Crashes on this line with - Program received signal: “EXC_BAD_ACCESS”. } } } And previous declarations from the header file: @interface CrowdViewController : UITableViewController { NSManagedObjectContext *managedObjectContext; NSFetchRequest *charactersRequest; NSEntityDescription *charactersEntity; NSMutableArray *characters; } I'm a bit perplexed and would really appreciate finding out what is going on.

    Read the article

  • iPhone CoreData join

    - by Ken
    Hi guys, long time reader, first time poster. (A link to this schema is located here) http://www.weeshsoft.com/pix/DatabasePic.jpg I'm trying to get all LanguageEntries from a database for a given category.categoryName and languageset.languageSetName e.g. NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"LanguageEntry" inManagedObjectContext:del.managedObjectContext]; [fetchRequest setEntity:entity]; NSString* predicateString = [NSString stringWithFormat:@"Category.categoryName = %@ AND LanguageSet.languageSetName = %@", @"Food", @"English####Spanish"]; fetchRequest.predicate = [NSPredicate predicateWithFormat:predicateString]; NSError *error = nil; NSArray* objects = [del.managedObjectContext executeFetchRequest:fetchRequest error:&error]; This always returns 0 objects. If I set the predicate string to match on one relationship (e.g. Category.categoryName = Food or languageSet.languageSetName = English####Spanish) it will return data. This is baffling, can anyone shed some light? -Ken

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9  | Next Page >