Search Results

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

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

  • Use CoreData or SQLite on iPhone?

    - by Hauke
    Since CoreData has become available for the iPhone in OS 3.0, is it meant to be the answer to data persistence and replace all need for direct SQLite? What reasons exist to still use SQLite? What are advantages/disadvantages of SQLite vs. CoreData?

    Read the article

  • NSMutableArray of NSString in CoreData(iPhone

    - by azia
    I have a class, which describe an object for parsing XML. This class contains NSStrings and NSMutableArrays of NSStrings.I want to store parsed data using CoreData. How should I write CoreData model to store such objects if there is no such data type like NSMutableArray? Is there any way?

    Read the article

  • how to fetch & store any column from coredata to array

    - by user440485
    Hi All, I am working on page(Lesson) has button called "AddToFavorite". when i click on this button lessonID,lessonHeading is added in the Coredata. - (NSFetchedResultsController *)fetchedResultsController { // Set up the fetched results controller if needed. if (fetchedResultsController != nil) { return fetchedResultsController; } // Create the fetch request for the entity. NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; // Edit the entity name as appropriate. NSEntityDescription *entity = [NSEntityDescription entityForName:@"Favorites" inManagedObjectContext:managedObjectContext]; [fetchRequest setEntity:entity]; // Edit the sort key as appropriate. NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"lessonHeading" ascending:YES]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [fetchRequest setSortDescriptors:sortDescriptors]; NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"lessonHeading" cacheName:@"Root"]; self.fetchedResultsController = aFetchedResultsController; self.fetchedResultsController.delegate = self; [aFetchedResultsController release]; [fetchRequest release]; [sortDescriptor release]; [sortDescriptors release]; return fetchedResultsController; } -(void)addToFavorites { UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil message:@"Lesson has been added successfully to your Favorite List" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; //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; [addingManagedObjectContext setPersistentStoreCoordinator:[[fetchedResultsController managedObjectContext] persistentStoreCoordinator]]; Favorites *fav = [NSEntityDescription insertNewObjectForEntityForName:@"Favorites" inManagedObjectContext:addingContext]; fav.lessonID=[[data objectAtIndex:count]objectForKey:@"LessonID"]; fav.lessonTitle=[[data objectAtIndex:count]objectForKey:@"LessonTitle"]; [self didFinishWithSave:YES]; [addingContext release]; } My problem is that i want to show an alert if this lessonID is already existing in the coreData. show guide me how i can match the current page lessonID with the existing lessonID's in the CoreData. I am using CoreData 1st time.so sory for any mistake ...& thanks for ypur help frnds.

    Read the article

  • Is this a tableView issue or a CoreData Issue

    - by monotreme
    I have a CoreData-driven navigation app and I'm trying to figure out why It's crashing. I've got a hierarchy which is 3 view Controllers deep, all related by coredata relatioships, like this. TableViewA =relationship= TableViewB =relationship= TableViewC I'm honestly a novice at core data and I think my problem lies in the fetched results controller. I have one in TableViewA and another in TableViewB, and no matter how deep I go, the console always cites TableViewB's fetched results controller methods after a crash. Is this the problem? What's happening specifically is if I launch my app and drill down into the hierarchy of one record, let's call it Record1, I can delete sub records to my hearts content. Gone! no problem! But the second I go back to TableViewA and drill down into a different record, let's call that one Record2, and try to delete it's subrecords my app crashes, with the console citing this code from TableViewB as the problem. - (void)controllerWillChangeContent:(NSFetchedResultsController *)controller { // The fetch controller is about to start sending change notifications, so prepare the table view for updates. [self.tableView beginUpdates]; } When I go into the debugger, the specific method it always has a problem with is: if (![x.managedObjectContext save:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } Just a confirmation of my idiocy with CoreData is all I'm looking for I think. Oh and how many ManagedObjectContexts should I have in an app of this type. I've been told I should have separate ones for adding content, which then should re-integrate into the main one. Is this true? Thanks!

    Read the article

  • Managing inverse relationships without CoreData

    - by Nathaniel Martin
    This is a question for Objective-J/Cappuccino, but I added the cocoa tag since the frameworks are so similar. One of the downsides of Cappuccino is that CoreData hasn't been ported over yet, so you have to make all your model objects manually. In CoreData, your inverse relationships get managed automatically for you... if you add an object to a to-many relationship in another object, you can traverse the graph in both directions. Without CoreData, is there any clean way to setup those inverse relationships automatically? For a more concrete example, let's take the typical Department and Employees example. To use rails terminology, a Department object has-many Employees, and an Employee belongs-to a Department. So our Department model has an NSMutableSet (or CPMutableSet ) "employees" that contains a set of Employees, and our Employee model has a variable "department" that points back to the Department model that owns it. Is there an easy way to make it so that, when I add a new Employee model into the set, the inverse relationship (employee.department) automatically gets set? Or the reverse: If I set the department model of an employee, then it automatically gets added to that department's employee set? Right know I'm making an object, "ValidatedModel" that all my models subclass, which adds a few methods that setup the inverse relationships, using KVO. But I'm afraid that I'm doing a lot of pointless work, and that there's already an easier way to do this. Can someone put my concerns to rest?

    Read the article

  • iPhone Development - CoreData runtime error

    - by Mustafa
    I'm facing a strange CoreData issue. Here's the log: 2010-04-07 15:59:36.913 MyProject[263:207] <MyEntity: 0x180370> (entity: MyEntity; id: 0x17e890 <x-coredata://0F55C533-41BD-4F09-9CCA-0CB304CAB065/MyEntity/p380> ; data: <fault>) 2010-04-07 15:59:36.918 MyProject[263:207] *** Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'The NSManagedObject with ID:0x17e890 <x-coredata://0F55C533-41BD-4F09-9CCA-0CB304CAB065/MyEntity/p380> has been invalidated.' I have a hierarchy of UITableViewControllers that use NSFetchedResultsController to populate the table, and when a particular row is selected, the detail view is shown. UITableView (MyMainEntity) UITableView (MyEntity) UITableView (MyEntity) detail view Both MyMainEntity UITableView and MyEntity UITableView use NSFetchedResultsController to show the records. Sometimes it crashes when i'm scrolling the tableView, and sometimes it crashes when i try to open the detail view. I can navigate to the MyEntity detail view multiple times before application crashes. What does this error mean? and how can i fix it!?

    Read the article

  • getting record from CoreData ?

    - by Meko
    Hi. I am trying to add value to CoreData from .plist and get from coreData and show them on UITable. I made take from .plist and send them to CoreData .But I cant take them from CoreData entity and set to some NSMutable array.. Here my codes Edit : SOLVED NSString *path = [[NSBundle mainBundle] pathForResource:@"FakeData" ofType:@"plist"]; NSArray *myArray=[[NSArray alloc] initWithContentsOfFile:path]; FlickrFetcher *flickrfetcher =[FlickrFetcher sharedInstance]; managedObjectContext =[flickrfetcher managedObjectContext]; for(NSDictionary *dict in myArray){ Photo *newPhoto = (Photo *)[NSEntityDescription insertNewObjectForEntityForName:@"Photo" inManagedObjectContext:managedObjectContext]; // set the attributes for the photo NSLog(@"Creating Photo: %@", [dict objectForKey:@"name"]); [newPhoto setName:[dict objectForKey:@"name"]]; [newPhoto setPath:[dict objectForKey:@"path"]]; NSLog(@"Person is: %@", [dict objectForKey:@"user"]); NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name ==%@",[dict objectForKey:@"user"]]; NSMutableArray *peopleArray = (NSMutableArray *)[flickrfetcher fetchManagedObjectsForEntity:@"Person" withPredicate:predicate]; NSEnumerator *enumerator = [peopleArray objectEnumerator]; Person *person; BOOL exists = FALSE; while (person = [enumerator nextObject]) { NSLog(@" Person is: %@ ", person.name); if([person.name isEqualToString:[dict objectForKey:@"user"]]) { exists = TRUE; NSLog(@"-- Person Exists : %@--", person.name); [newPhoto setPerson:person]; } } // if person does not already exist then add the person if (!exists) { Person *newPerson = (Person *)[NSEntityDescription insertNewObjectForEntityForName:@"Person" inManagedObjectContext:managedObjectContext]; // create the person [newPerson setName:[dict objectForKey:@"user"]]; NSLog(@"-- Person Created : %@--", newPerson.name); // associate the person with the photo [newPhoto setPerson:newPerson]; } //THis IS myArray that I want to save value in it and them show them in UITABLE personList=[[NSMutableArray alloc]init]; NSLog(@"lllll %@",[personList objectAtIndex:0]); // save the data NSError *error; if (![managedObjectContext save:&error]) { // Handle the error. NSLog(@"Unresolved error %@, %@", error, [error userInfo]); exit(-1); } } //To access core data objects you can try the following: // setup our fetchedResultsController fetchedResultsController = [flickrfetcher fetchedResultsControllerForEntity:@"Person" withPredicate:nil]; // execute the fetch NSError *error; BOOL success = [fetchedResultsController performFetch:&error]; if (!success) { // Handle the error. NSLog(@"Unresolved error %@, %@", error, [error userInfo]); exit(-1); } // save our data //HERE PROBLEM THAT I DONW KNOW WHERE IT IS SAVING //[personList addObject:(NSMutableArray *)[fetchedResultsController fetchedObjects]]; [self setPersonList:(NSMutableArray *)[fetchedResultsController fetchedObjects]]; } Here my tableview function - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"ss %d",[personList count]); static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } cell.textLabel.text=[personList objectAtIndex:indexPath.row]; // Set up the cell... return cell; }

    Read the article

  • CoreData: managedObjectContext not being created

    - by PruitIgoe
    I had to add core data to an existing project but I am having issues with the managedObjectContext... in prefix.pch I have this: #import <Availability.h> #ifndef __IPHONE_5_0 #warning "This project uses features only available in iOS SDK 5.0 and later." #endif #ifdef __OBJC__ #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> #import <CoreData/CoreData.h> #endif ... in my appDelegate.h I have this: #import <UIKit/UIKit.h> #import "AppViewController.h" #import "DDLog.h" #import "DDASLLogger.h" #import "DDFileLogger.h" #import "DDTTYLogger.h" #import "KIP_LogManager.h" @interface AppDelegate : UIResponder <UIApplicationDelegate> { DDFileLogger* fileLogger; /*coredata*/ NSManagedObjectModel* managedObjectModel; NSManagedObjectContext* managedObjectContext; NSPersistentStoreCoordinator* persistentStoreCoordinator; } @property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) AppViewController* viewController; @property (readonly, strong, nonatomic) NSManagedObjectContext* managedObjectContext; @property (readonly, strong, nonatomic) NSManagedObjectModel* managedObjectModel; @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator* persistentStoreCoordinator; - (void)setupLogging; - (NSString *)applicationDocumentsDirectory; in appDelegate.m this: @synthesize managedObjectContext = _managedObjectContext; @synthesize managedObjectModel = _managedObjectModel; @synthesize persistentStoreCoordinator = _persistentStoreCoordinator; ... - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //establish lumberjack logging [self setupLogging]; DDLogVerbose(@"\n\n*********************\nNEW LOG SESSION\n**********************\n\n"); //set root view controller self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.viewController = [[AppViewController alloc] init]; self.window.rootViewController = self.viewController; self.viewController.managedObjectContext = _managedObjectContext; return YES; } ... #pragma mark - CoreData Stack - (NSManagedObjectContext *)managedObjectContext { if (_managedObjectContext != nil) { return _managedObjectContext; } NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; if (coordinator != nil) { _managedObjectContext = [[NSManagedObjectContext alloc] init]; [_managedObjectContext setPersistentStoreCoordinator:coordinator]; } return _managedObjectContext; } // Returns the managed object model for the application. // If the model doesn't already exist, it is created from the application's model. - (NSManagedObjectModel *)managedObjectModel { if (_managedObjectModel != nil) { return _managedObjectModel; } NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"SPI_PAC" withExtension:@"momd"]; _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; return _managedObjectModel; } - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (persistentStoreCoordinator != nil) { return persistentStoreCoordinator; } NSMutableString* strDocsDirector = [[NSMutableString alloc] initWithString:[self applicationDocumentsDirectory]]; [strDocsDirector appendString:@"/SPI_PAC.sqlite"]; NSURL* storeURL = [NSURL URLWithString:strDocsDirector]; NSError *error = nil; persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; if(![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) { /*Error for store creation should be handled in here*/ } return persistentStoreCoordinator; } - (NSString *)applicationDocumentsDirectory { return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; } in the view controller, viewDidLoad I am logging the passed managedObjectContext and am getting null returned. Obviously I am missing something but not sure what? In viewcontroller.h I have: @property (nonatomic, retain) NSManagedObjectModel* managedObjectModel; @property (nonatomic, retain) NSManagedObjectContext* managedObjectContext; @property (nonatomic, retain) NSPersistentStoreCoordinator* persistentStoreCoordinator; and in the viewcontroller.m: @synthesize managedObjectContext = managedObjectContext; ... DDLogVerbose(@"%@", managedObjectContext);

    Read the article

  • Load CoreData objects' string property into UIPickerView

    - by OscarTheGrouch
    Hello Currently I have an entity named "Events" in a CoreData app. "Events" has one string property named "eventName". In the -(void)viewDidLoad I am trying to Fetch all the "Events" objects and load their "eventName" by alphabetical order into a UIPickerView. The ultimate end goal is through the use of a textField, buttons and the pickerView being add new objects in and remove unwanted objects out. Basically turning the UIPickerView into a UITableView. Currently I am able to save objects to the CoreData store, but am not able to pull them/their properties out into the UIPickerView. I am willing and able to share the project source code to anyone who wants it, or is willing to look at it to help out. thanks Chris

    Read the article

  • Tree data structure in iphone with coredata

    - by ebabchick
    Hi, I am looking to store a tree structure in CoreData for iphone. Can someone give me some tips on the best way to go about this? Basically I want to have a bunch of folders that people can dive into in a table view, and I want to have leaves of the tree be photos. The thing is, I want to be able to let the user edit these folders on-the-fly and add folders and content (photos) at their discretion. I'm relatively new to CoreData. Any help would be appreciated. Thanks.

    Read the article

  • Updates to NSDictionary attribute in CoreData not saving

    - by sfkaos
    I have created an Entity in CoreData that includes a Transformable attribute type implemented as an NSDictionary. The NSDictionary attribute only contains values of a custom class. The properties of the custom class are all of type NSString. The custom class complies with NSCoding implementing: -(void)encodeWithCoder:(NSCoder*)coder; -(id)initWithCoder:(NSCoder *)coder When saving the Entity for the first time all attributes including the Transformable (NSDictionary) type are properly saved in the DB. When the same Entity is fetched from the DB and updated (including the Transformable attribute) it seems to be updated properly. However, when the app is closed and then reopened fetching the Entity does not show the updated Transformable attribute-type though the rest of the attributes of type NSDate and NSString are up-to-date. The Transformable attribute is the original saved value not the updated value. Is this a problem with KVO or am I missing something else when trying to save an NSDictionary filled with a custom class to CoreData?

    Read the article

  • JSON to Persistent Data Store (CoreData, etc.)

    - by Bryan Veloso
    All of the data on my application is pulled through an API via JSON. The nature of a good percentage of this data is that it doesn't change very often. So to go and make JSON requests to get a list of data that doesn't change much didn't seem all that appealing. I'm looking for the most sensible option to have this JSON saved onto the iPhone in some sort of persistent data store. Obviously one plus of persisting the data would be to provide it when the phone can't access the API. I've looked at a few examples of having JSON and CoreData interact, for example, but it seems that they only describe transforming NSManagedObjects into JSON. If I can transform JSON into CoreData, my only problem would be being able to change that data when the data from the API does change. (Or, maybe this is all just silly.)

    Read the article

  • Importing large datasets on iPhone using CoreData

    - by Matthes
    Hi there, I'm facing very annoying problem. My iPhone app is loading it's data from a network server. Data are sent as plist and when parsed, it neeeds to be stored to SQLite db using CoreData. Issue is that in some cases those datasets are too big (5000+ records) and import takes way too long. More on that, when iPhone tries to suspend the screen, Watchdog kills the app because it's still processing the import and does not respond up to 5 seconds, so import is never finished. I used all recommended techniques according to article "Efficiently Importing Data" http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/CoreData/Articles/cdImporting.html and other docs concerning this, but it's still awfully slow. Solution I'm looking for is to let app suspend, but let import run in behind (better one) or to prevent attempts to suspend the app at all. Or any better idea is welcomed too. Any tips on how to overcome these issues are highly appreciated! Thanks

    Read the article

  • How to properly use CoreData validation & error framework ?

    - by Xav
    I've created a model in Xcode, and for various attributes I have minimum & maximum values defined and that are enforced by coreData at runtime. I'm using NSManagedObject validateValue:forKey:error to check for user input values. I was a bit disappointed to see that the localized error message is not specific, and I get a "The operation couldn't be completed. (Cocoa error 1620)" for too small values and a "The operation couldn't be completed. (Cocoa error 1610)" for too large values. It's written in the coreData documentation that "you can localize most aspects of a managed object model, including entity and property names and error messages". Unfortunately it's not very detailed on how you implement it for error messages. So How do you customize error message ? How do you localize them ? Is it possible to customize it in a way where it will mentioned the reference value ex: "Value should be lower than %@" or "Value should be higher than %@" ?

    Read the article

  • Reverting CoreData data

    - by ndg
    I have an NSTableView which is populated via a CoreData-backed NSArrayController. Users are able to edit any field they choose within the NSTableView. When they select the rows that they have modified and press a button, the data is sent to a third-party webservice. Provided the webservice accepts the updated values, I want to commit those values to my persistent store. If, however, the webservice returns an error (or simply fails to return), I want the edited fields to revert to their original values. To complicate matters, I have a number of other editable controls, backed by CoreData, which do not need to resort to this behaviour. I believe the solution to this problem revolves around the creation of a secondary Managed Object context, which I would use only for values edited within that particularly NSTableView. But I'm confused as to how the two MOC would interact with each other. What's the best solution to this problem?

    Read the article

  • CoreData and many NSArrayController

    - by unixo
    In my CoreData Application, I've an outline view on left of main window, acting as source list (like iTunes); on the right I display a proper view, based on outline selection. Each view has its components, such as table view, connected to array controller, owned by the specific view. Very often different views display same data, for example, a table view of the same entity. From a performance point of view, is better to have a single array controller per entity and share it between all views or does CoreData cache avoid memory waste?

    Read the article

  • How can I encrypt CoreData contents on an iPhone

    - by James A. Rosen
    I have some information I'd like to store statically encrypted on an iPhone application. I'm new to iPhone development, some I'm not terribly familiar with CoreData and how it integrates with the views. I have the data as JSON, though I can easily put it into a SQLITE3 database or any other backing data format. I'll take whatever is easiest (a) to encrypt and (b) to integrate with the iPhone view layer. The user will need to enter the password to decrypt the data each time the app is launched. The purpose of the encryption is to keep the data from being accessible if the user loses the phone. For speed reasons, I would prefer to encrypt and decrypt the entire file at once rather than encrypting each individual field in each row of the database. Note: this isn't the same idea as Question 929744, in which the purpose is to keep the user from messing with or seeing the data. The data should be perfectly transparent when in use. Also note: I'm willing to use SQLCipher to store the data, but would prefer to use things that already exist on the iPhone/CoreData framework rather than go through the lengthy build/integration process involved.

    Read the article

  • CoreData : store images to DB or not?

    - by Meko
    Hi.I am making an app that it takes photos from web site for some Username and shows it on UITable with username then when clicking user name it shows photos for this user and then clicking to name of photo it shows full screen photo. My question is I am using NSData to get photos from internet.Am I have to save also those data to CoreDAta? I am using like when pressing name of user it again creates NSData and downloads photos from internet and shows them on UTable. And it takes time. What is good approach? and How can save this images to CoreDAta? I am using this method NSData *imageData=[flickr dataForPhotoID:firstPhoto.id fromFarm:firstPhoto.farm onServer:firstPhoto.server withSecret:firstPhoto.secret inFormat: FlickrFetcherPhotoFormatSquare]; and here definition of dataForPtohoID method - (NSData *)dataForPhotoID:(NSString *)photoID fromFarm:(NSString *)farm onServer:(NSString *)server withSecret:(NSString *)secret inFormat:(FlickrFetcherPhotoFormat)format { #if TEST_HIGH_NETWORK_LATENCY sleep(1); #endif NSString *formatString; switch (format) { case FlickrFetcherPhotoFormatSquare: formatString = @"s"; break; case FlickrFetcherPhotoFormatLarge: formatString = @"b"; break; } NSString *photoURLString = [NSString stringWithFormat:@"http://farm%@.static.flickr.com/%@/%@_%@_%@.jpg", farm, server, photoID, secret, formatString]; NSURL *url = [NSURL URLWithString:photoURLString]; return [NSData dataWithContentsOfURL:url]; }

    Read the article

  • Calling NSFetchedResultsController & CoreData experts

    - by JK
    I am having a few nagging issues with NSFetchedResultsController and CoreData, any of which I would be very grateful to get help on. Issue 1 - Updates: I update my store on a background thread which results in certain rows being delete, inserted or updated. The changes are merged into the context on the main thread using the "mergeChangesFromContextDidSaveNotification:" method. Inserts and deletes are updated properly, but updates are not (e.g. the cell label is not updated with the change) although I have confirmed the updates to come through the contextDidSaveNotifcation, exactly like the inserts and deleted. My current workaround is to temporarily change the staleness interval of the context to 0, but this does not seem like the ideal solution. Issue 2 - Deleting objects: My fetch batch size is 20. If an object is deleted by the background thread which is in the first 20 rows, everything works fine. But if the object is after the first 20 rows and the table is scrolled down, a "CoreData could not fulfill a fault" error is raised. I have tried resaving the context and reperforming the frc fetch - all to no avail. Note: In this scenario, the frc delegate method "didChangeObject...." is not called for the delete - I assume this is because the object in question had not been faulted at that time (as it is was outside the initial fetch range). But for some reason, the context still thinks the object is around, although is has been deleted from the store. Issue 3 - Deleting sections : When the deletion of a row leads to the deletion of a section, I have gotten the "invalid number of rows in section???" error. I have worked around this by removing the "reloadSection" line from the NSFetchedResultsChangeMove: section and replacing it with "[tableView insertRowsAtIndexPaths...." This seems to work, but once again, I am not sure if this is the best solution. Any help would be greatly appreciated. Thank you!

    Read the article

  • iPhone NSDate - get time in milliseconds and store in coredata

    - by satyam
    I'm implementing iphone app with coredata functionality. I've an attribute in entity "NSDate" which stores the date and time when the record is added. I'm adding records at a faster rate. About 1 record per 25 milli seconds I want to store the date along with milli seconds so that I can retrieve the data in descending order. How can I do this?

    Read the article

  • Securing Coredata objects

    - by Abraham Durairaj
    I am working on an application which has got some sensitive information. I am aware that it would be difficult for a layman to hack into iphone to get the information. If I use SQLite directly I have something called SQLite Cipher to encrypt / encode the database. Is there anyway where I can have the same way of encrypting the coredata so it makes it hard for hackers to get into the data. Can someone shed some light on this? Thanks in Advance

    Read the article

  • iPhone crash on CoreData save

    - by davetron5000
    This is a different situation than this question, as the solution provided doesn't work and the stack is different. Periodical crash when I save data using coredata. The stack trace isn't 100% clear on where this is happening, but I'm certain it's this routine that's being called. It's either the save: in this method or the one following. Code: -(void)saveWine { if ([self validInfo]) { Wine *wine = (Wine *)wineToEdit; if (wine == nil) { wine = (Wine *)[NSEntityDescription insertNewObjectForEntityForName:@"Wine" inManagedObjectContext:self.managedObjectContext]; } wine.uuid = [Utils createUUID]; wine.name = self.wineNameField.text; wine.vineyard = self.vineyardField.text; wine.vintage = [[self numberFormatter] numberFromString:self.vintageField.text]; wine.timeStamp = [NSDate date]; wine.rating = [NSNumber numberWithInt:self.ratingControl.selectedSegmentIndex]; wine.partnerRating = [NSNumber numberWithInt:self.partnerRatingControl.selectedSegmentIndex]; wine.varietal = self.currentVarietal; wine.tastingNotes = self.currentTastingNotes; wine.dateTasted = self.currentDateTasted; wine.tastingLocation = [[ReferenceDataAccessor defaultReferenceDataAccessor] addEntityForType:TASTING_LOCATION withName:self.currentWhereTasted]; id type = [[ReferenceDataAccessor defaultReferenceDataAccessor] entityForType:WINE_TYPE withOrdinal:self.typeControl.selectedSegmentIndex]; wine.type = type; NSError *error; NSLog(@"Saving %@",wine); if (![self.managedObjectContext save:&error]) { [Utils showAlertMessage:@"There was a problem saving your wine; try restarting the app" withTitle:@"Problem saving"]; NSLog(@"Error while saving new wine %@, %@", error, [error userInfo]); } } else { NSLog(@"ERROR - someone is calling saveWine with invalid info!!"); } } Code for addEntityForType:withName:: -(id)addEntityForType:(NSString *)type withName:(NSString *)name { if ([Utils isStringBlank:name]) { return nil; } id existing = [[ReferenceDataAccessor defaultReferenceDataAccessor] entityForType:type withName:name]; if (existing != nil) { NSLog(@"%@ with name %@ already exists",type,name); return existing; } NSManagedObject *newEntity = [NSEntityDescription insertNewObjectForEntityForName:type inManagedObjectContext:self.managedObjectContext]; [newEntity setValue:name forKey:@"name"]; NSError *error; if (![self.managedObjectContext save:&error]) { [Utils showAlertMessage:[NSString stringWithFormat:@"There was a problem saving a %@",type] withTitle:@"Database Probem"]; [Utils logErrorFully:error forOperation:[NSString stringWithFormat:@"saving new %@",type ]]; } return newEntity; } Stack trace: Thread 0 Crashed: 0 libSystem.B.dylib 0x311de2d4 __kill + 8 1 libSystem.B.dylib 0x311de2c4 kill + 4 2 libSystem.B.dylib 0x311de2b6 raise + 10 3 libSystem.B.dylib 0x311f2d72 abort + 50 4 libstdc++.6.dylib 0x301dea20 __gnu_cxx::__verbose_terminate_handler() + 376 5 libobjc.A.dylib 0x319a2594 _objc_terminate + 104 6 libstdc++.6.dylib 0x301dcdf2 __cxxabiv1::__terminate(void (*)()) + 46 7 libstdc++.6.dylib 0x301dce46 std::terminate() + 10 8 libstdc++.6.dylib 0x301dcf16 __cxa_throw + 78 9 libobjc.A.dylib 0x319a14c4 objc_exception_throw + 64 10 CoreData 0x3526e83e -[NSManagedObjectContext save:] + 1098 11 Wine Brain 0x0000651e 0x1000 + 21790 12 Wine Brain 0x0000525c 0x1000 + 16988 13 Wine Brain 0x00004894 0x1000 + 14484 14 Wine Brain 0x00008716 0x1000 + 30486 15 CoreFoundation 0x31477fe6 -[NSObject(NSObject) performSelector:withObject:withObject:] + 18 16 UIKit 0x338c14a6 -[UIApplication sendAction:to:from:forEvent:] + 78 17 UIKit 0x3395c7ae -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 86 18 CoreFoundation 0x31477fe6 -[NSObject(NSObject) performSelector:withObject:withObject:] + 18 19 UIKit 0x338c14a6 -[UIApplication sendAction:to:from:forEvent:] + 78 20 UIKit 0x338c1446 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 26 21 UIKit 0x338c1418 -[UIControl sendAction:to:forEvent:] + 32 22 UIKit 0x338c116a -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 350 23 UIKit 0x338c19c8 -[UIControl touchesEnded:withEvent:] + 336 24 UIKit 0x338b734e -[UIWindow _sendTouchesForEvent:] + 362 25 UIKit 0x338b6cc8 -[UIWindow sendEvent:] + 256 26 UIKit 0x338a1fc0 -[UIApplication sendEvent:] + 292 27 UIKit 0x338a1900 _UIApplicationHandleEvent + 5084 28 GraphicsServices 0x35d66efc PurpleEventCallback + 660 29 CoreFoundation 0x314656f8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 20 30 CoreFoundation 0x314656bc __CFRunLoopDoSource1 + 160 31 CoreFoundation 0x31457f76 __CFRunLoopRun + 514 32 CoreFoundation 0x31457c80 CFRunLoopRunSpecific + 224 33 CoreFoundation 0x31457b88 CFRunLoopRunInMode + 52 34 GraphicsServices 0x35d664a4 GSEventRunModal + 108 35 GraphicsServices 0x35d66550 GSEventRun + 56 36 UIKit 0x338d5322 -[UIApplication _run] + 406 37 UIKit 0x338d2e8c UIApplicationMain + 664 38 Wine Brain 0x000021ba 0x1000 + 4538 39 Wine Brain 0x00002184 0x1000 + 4484 I have no idea why my app's memory locations aren't being symbolocated, but the code paths lead to only two manavedObjectContext save: calls. The time this happend, addEntityForType was called all the way through, creating a new object for the "whereTasted" entity, before the final save: on the entire wine object. When I go through the same procedure again, it works fine. This leads me to believe it's something to do with the app having been run for a while when adding a new location, but I'm not sure. Any thoughts on how I can debug this and get more info the next time this happens?

    Read the article

  • Records not being saved to core data sqlite file

    - by esd100
    I'm a complete newbie when it comes to iOS programming and much less Core Data. It's rather non-intuitive for me, as I really came into my own with programming with MATLAB, which I guess is more of a 'scripting' language. At any rate, my problem is that I had no idea what I had to do to create a database for my application. So I read a little bit and thought I had to create a SQL database of my stuff and then import it. Long story short, I created a SQLite db and I want to use the work I have already done to import stuff into my CoreData database. I tried exporting to comma-delimited files and xml files and reading those in, but I didn't like it and it seemed like an extra step that I shouldn't need to do. So, I imported the SQLite database into my resources and added the sqlite framework. I have my core data model setup and it is setting up the SQLite database for the model correctly in the background. When I run through my program to add objects to my entities, it seems to work and I can even fetch results afterward. However, when I inspect the Core Data Database SQLite file, no records have been saved. How is it possible for it to fetch results but not save them to the database? - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ //load in the path for resources NSString *paths = [[NSBundle mainBundle] resourcePath]; NSString *databaseName = @"histology.sqlite"; NSString *databasePath = [paths stringByAppendingPathComponent:databaseName]; [self createDatabase:databasePath ]; NSError *error; if ([[self managedObjectContext] save:&error]) { NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]); } // Test listing all CELLS from the store NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entityMO = [NSEntityDescription entityForName:@"CELL" inManagedObjectContext:[self managedObjectContext]]; [fetchRequest setEntity:entityMO]; NSArray *fetchedObjects = [[self managedObjectContext] executeFetchRequest:fetchRequest error:&error]; for (CELL *cellName in fetchedObjects) { //NSLog(@"cellName: %@", cellName); } -(void) createDatabase:databasePath { NSLog(@"The createDatabase function was entered."); NSLog(@"The databasePath is %@ ",[databasePath description]); // Setup the database object sqlite3 *histoDatabase; // Open the database from filessytem if(sqlite3_open([databasePath UTF8String], &histoDatabase) == SQLITE_OK) { NSLog(@"The database was opened"); // Setup the SQL Statement and compile it for faster access const char *sqlStatement = "SELECT * FROM CELL"; sqlite3_stmt *compiledStatement; if(sqlite3_prepare_v2(histoDatabase, sqlStatement, -1, &compiledStatement, NULL) != SQLITE_OK) { NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(histoDatabase)); } if(sqlite3_prepare_v2(histoDatabase, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) { // Loop through the results and add them to cell MO array while(sqlite3_step(compiledStatement) == SQLITE_ROW) { CELL *cellMO = [NSEntityDescription insertNewObjectForEntityForName:@"CELL" inManagedObjectContext:[self managedObjectContext]]; if (sqlite3_column_type(compiledStatement, 0) != SQLITE_NULL) { cellMO.cellName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)]; } else { cellMO.cellName = @"undefined"; } if (sqlite3_column_type(compiledStatement, 1) != SQLITE_NULL) { cellMO.cellDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)]; } else { cellMO.cellDescription = @"undefined"; } NSLog(@"The contents of NSString *cellName = %@",[cellMO.cellName description]); } } // Release the compiled statement from memory sqlite3_finalize(compiledStatement); } sqlite3_close(histoDatabase); } I have a feeling that it has something to do with the timing of opening/closing both of the databases? Attached I have some SQL debugging output to the terminal 2012-05-28 16:03:39.556 MedPix[34751:fb03] The createDatabase function was entered. 2012-05-28 16:03:39.557 MedPix[34751:fb03] The databasePath is /Users/jack/Library/Application Support/iPhone Simulator/5.1/Applications/A6B2A79D-BA93-4E24-9291-5B7948A3CDF4/MedPix.app/histology.sqlite 2012-05-28 16:03:39.559 MedPix[34751:fb03] The database was opened 2012-05-28 16:03:39.560 MedPix[34751:fb03] The database was prepared 2012-05-28 16:03:39.575 MedPix[34751:fb03] CoreData: annotation: Connecting to sqlite database file at "/Users/jack/Library/Application Support/iPhone Simulator/5.1/Applications/A6B2A79D-BA93-4E24-9291-5B7948A3CDF4/Documents/MedPix.sqlite" 2012-05-28 16:03:39.576 MedPix[34751:fb03] CoreData: annotation: creating schema. 2012-05-28 16:03:39.577 MedPix[34751:fb03] CoreData: sql: pragma page_size=4096 2012-05-28 16:03:39.578 MedPix[34751:fb03] CoreData: sql: pragma auto_vacuum=2 2012-05-28 16:03:39.630 MedPix[34751:fb03] CoreData: sql: BEGIN EXCLUSIVE 2012-05-28 16:03:39.631 MedPix[34751:fb03] CoreData: sql: SELECT TBL_NAME FROM SQLITE_MASTER WHERE TBL_NAME = 'Z_METADATA' 2012-05-28 16:03:39.632 MedPix[34751:fb03] CoreData: sql: CREATE TABLE ZCELL ( Z_PK INTEGER PRIMARY KEY, Z_ENT INTEGER, Z_OPT INTEGER, ZCELLDESCRIPTION VARCHAR, ZCELLNAME VARCHAR ) ... 2012-05-28 16:03:39.669 MedPix[34751:fb03] CoreData: annotation: Creating primary key table. 2012-05-28 16:03:39.671 MedPix[34751:fb03] CoreData: sql: CREATE TABLE Z_PRIMARYKEY (Z_ENT INTEGER PRIMARY KEY, Z_NAME VARCHAR, Z_SUPER INTEGER, Z_MAX INTEGER) 2012-05-28 16:03:39.672 MedPix[34751:fb03] CoreData: sql: INSERT INTO Z_PRIMARYKEY(Z_ENT, Z_NAME, Z_SUPER, Z_MAX) VALUES(1, 'CELL', 0, 0) ... 2012-05-28 16:03:39.701 MedPix[34751:fb03] CoreData: sql: CREATE TABLE Z_METADATA (Z_VERSION INTEGER PRIMARY KEY, Z_UUID VARCHAR(255), Z_PLIST BLOB) 2012-05-28 16:03:39.702 MedPix[34751:fb03] CoreData: sql: SELECT TBL_NAME FROM SQLITE_MASTER WHERE TBL_NAME = 'Z_METADATA' 2012-05-28 16:03:39.703 MedPix[34751:fb03] CoreData: sql: DELETE FROM Z_METADATA WHERE Z_VERSION = ? 2012-05-28 16:03:39.704 MedPix[34751:fb03] CoreData: sql: INSERT INTO Z_METADATA (Z_VERSION, Z_UUID, Z_PLIST) VALUES (?, ?, ?) 2012-05-28 16:03:39.705 MedPix[34751:fb03] CoreData: sql: COMMIT 2012-05-28 16:03:39.710 MedPix[34751:fb03] CoreData: sql: pragma cache_size=200 2012-05-28 16:03:39.711 MedPix[34751:fb03] CoreData: sql: SELECT Z_VERSION, Z_UUID, Z_PLIST FROM Z_METADATA 2012-05-28 16:03:39.712 MedPix[34751:fb03] The contents of NSString *cellName = Beta Cell 2012-05-28 16:03:39.712 MedPix[34751:fb03] The contents of NSString *cellName = Gastric Chief Cell ... 2012-05-28 16:03:39.714 MedPix[34751:fb03] The database was prepared 2012-05-28 16:03:39.764 MedPix[34751:fb03] The createDatabase function has finished. Now fetching. 2012-05-28 16:03:39.765 MedPix[34751:fb03] CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZCELLDESCRIPTION, t0.ZCELLNAME FROM ZCELL t0 2012-05-28 16:03:39.766 MedPix[34751:fb03] CoreData: annotation: sql connection fetch time: 0.0008s 2012-05-28 16:03:39.767 MedPix[34751:fb03] CoreData: annotation: total fetch execution time: 0.0016s for 0 rows. 2012-05-28 16:03:39.768 MedPix[34751:fb03] cellName: <CELL: 0x6bbc120> (entity: CELL; id: 0x6bbc160 <x-coredata:///CELL/t57D10DDD-74E2-474F-97EE-E3BD0FF684DA34> ; data: { cellDescription = "S cells are cells which release secretin, found in the jejunum and duodenum. They are stimulated by a drop in pH to 4 or below in the small intestine's lumen. The released secretin will increase the s"; cellName = "S Cell"; organs = ( ); specimens = ( ); systems = ( ); tissues = ( ); }) ... Sections were cut short to abbreviate. But note that the fetch results contain information, but it says that total fetch execution was for "0" rows? How can that be? Any help will be greatly appreciated, especially detailed explanations. :) Thanks.

    Read the article

  • Using mergedModelFromBundles: and versioning (CoreData)

    - by charlax
    Hi everybody, I'm trying to use the migration feature in CoreData. I've followed the Apple Documentation. I have a problem in the following method: /** Returns the managed object model for the application. If the model doesn't already exist, it is created by merging all of the models found in the application bundle. */ - (NSManagedObjectModel *)managedObjectModel { if (managedObjectModel != nil) { return managedObjectModel; } /* * NSInvalidArgumentException', reason: '*** -[NSCFArray insertObject:atIndex:]: attempt to insert nil' * 2010-02-17 16:27:15.338 Patrimoine[3037:207] */ managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain]; return managedObjectModel; } It appears that there is the same problem on http://iphonedevelopment.blogspot.com/2009/09/core-data-migration-problems.html Yet I did choose the method Apple suggests, by using the menu option "Add Model Version". Do you have any idea?

    Read the article

  • How to get objects after CoreData Context merged

    - by Emmettoc
    Hi, I tried to save data and merge with CoreData and multi-thread for iPhone app. But I can't get managed objects in the main thread after merging. I wrote code just like this: [managedObjectContext performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:) withObject:notification waitUntilDone:YES]; [self performSelectorOnMainThread:@selector(didMerged:) withObject:objectIds waitUntilDone:YES]; So I tried to pass objectIds to get NSManagedObject instances in the main thread which were generated in another thread. At first I tried "objectWithId" method but it generated fault objects. Then I tried "existingObjectWithID" method but it generated objects partly and others were nil with following Error: [Error] Error Domain=NSCocoaErrorDomain Code=133000 "Operation could not be completed. (Cocoa error 133000.)" What is wrong? Is there any way how to retrieve all objects by objectIds after merging in another thread? Thank you.

    Read the article

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