Search Results

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

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

  • ORM on iPhone. More simple than CoreData.

    - by Alexander Babaev
    The question is rather simple. I know that there is SQLite. There is Core Data also. But I need something in between. More object-oriented than SQLite API and simplier than Core Data. Main points are: I need access to stored entities only by id. No queries required. I need to store items of a single type, it means that I can use only one table if I choose SQLite. I want automatic object-relational conversion. Or object-storage if the storage is not relational. I can use object archiving, but I have to implement things (NSArchiver). But I want to write some kind of class and get persistence automatically. As it can be done with Hibernate/ActiveRecord/Core Data/etc. Thanks.

    Read the article

  • How do you populate a NSArrayController with CoreData rows programmatically?

    - by Andrew McCloud
    After several hours/days of searching and diving into example projects i've concluded that I need to just ask. If I bind the assetsView (IKImageBrowserView) directly to an IB instance of NSArrayController everything works just fine. - (void) awakeFromNib { library = [[NSArrayController alloc] init]; [library setManagedObjectContext:[[NSApp delegate] managedObjectContext]]; [library setEntityName:@"Asset"]; NSLog(@"%@", [library arrangedObjects]); NSLog(@"%@", [library content]); [assetsView setDataSource:library]; [assetsView reloadData]; } Both NSLogs are empty. I know i'm missing something... I just don't know what. The goal is to eventually allow multiple instances of this view's "library" filtered programmatically with a predicate. For now i'm just trying to have it display all of the rows for the "Asset" entity. Addition: If I create the NSArrayController in IB and then try to log [library arrangedObjects] or manually set the data source for assetsView I get the same empty results. Like I said earlier, if I bind library.arrangedObjects to assetsView.content (IKImageBrowserView) in IB - with same managed object context and same entity name set by IB - everything works as expected. - (void) awakeFromNib { // library = [[NSArrayController alloc] init]; // [library setManagedObjectContext:[[NSApp delegate] managedObjectContext]]; // [library setEntityName:@"Asset"]; NSLog(@"%@", [library arrangedObjects]); NSLog(@"%@", [library content]); [assetsView setDataSource:library]; [assetsView reloadData]; }

    Read the article

  • Xcode's colored console output

    - by krasnyk
    Is possible to format/color the output in the Xcode console? I know that you can do that while debugging CoreData on Mac by setting: com.apple.CoreData.SQLDebug 3 and com.apple.CoreData.SyntaxColoredLogging YES What with our own logs, can we color/format them too somehow?

    Read the article

  • Fixing predicated NSFetchedResultsController/NSFetchRequest performance with SQLite backend?

    - by Jaanus
    I have a series of NSFetchedResultsControllers powering some table views, and their performance on device was abysmal, on the order of seconds. Since it all runs on main thread, it's blocking my app at startup, which is not great. I investigated and turns out the predicate is the problem: NSPredicate *somePredicate = [NSPredicate predicateWithFormat:@"ANY somethings == %@", something]; [fetchRequest setPredicate:somePredicate]; I.e the fetch entity, call it "things", has a many-to-many relation with entity "something". This predicate is a filter that limits the results to only things that have a relation with a particular "something". When I removed the predicate for testing, fetch time (the initial performFetch: call) dropped (for some extreme cases) from 4 seconds to around 100ms or less, which is acceptable. I am troubled by this, though, as it negates a lot of the benefit I was hoping to gain with Core Data and NSFRC, which otherwise seems like a powerful tool. So, my question is, how can I optimize this performance? Am I using the predicate wrong? Should I modify the model/schema somehow? And what other ways there are to fix this? Is this kind of degraded performance to be expected? (There are on the order of hundreds of <1KB objects.) EDIT WITH DETAILS: Here's the code: [fetchRequest setFetchLimit:200]; NSLog(@"before fetch"); BOOL success = [frc performFetch:&error]; if (!success) { NSLog(@"Fetch request error: %@", error); } NSLog(@"after fetch"); Updated logs (previously, I had some application inefficiencies degrading the performance here. These are the updated logs that should be as close to optimal as you can get under my current environment): 2010-02-05 12:45:22.138 Special Ppl[429:207] before fetch 2010-02-05 12:45:22.144 Special Ppl[429:207] CoreData: sql: SELECT DISTINCT 0, t0.Z_PK, t0.Z_OPT, <model fields> FROM ZTHING t0 LEFT OUTER JOIN Z_1THINGS t1 ON t0.Z_PK = t1.Z_2THINGS WHERE t1.Z_1SOMETHINGS = ? ORDER BY t0.ZID DESC LIMIT 200 2010-02-05 12:45:22.663 Special Ppl[429:207] CoreData: annotation: sql connection fetch time: 0.5094s 2010-02-05 12:45:22.668 Special Ppl[429:207] CoreData: annotation: total fetch execution time: 0.5240s for 198 rows. 2010-02-05 12:45:22.706 Special Ppl[429:207] after fetch If I do the same fetch without predicate (by commenting out the two lines in the beginning of the question): 2010-02-05 12:44:10.398 Special Ppl[414:207] before fetch 2010-02-05 12:44:10.405 Special Ppl[414:207] CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, <model fields> FROM ZTHING t0 ORDER BY t0.ZID DESC LIMIT 200 2010-02-05 12:44:10.426 Special Ppl[414:207] CoreData: annotation: sql connection fetch time: 0.0125s 2010-02-05 12:44:10.431 Special Ppl[414:207] CoreData: annotation: total fetch execution time: 0.0262s for 200 rows. 2010-02-05 12:44:10.457 Special Ppl[414:207] after fetch 20-fold difference in times. 500ms is not that great, and there does not seem to be a way to do it in background thread or otherwise optimize that I can think of. (Apart from going to a binary store where this becomes a non-issue, so I might do that. Binary store performance is consistently ~100ms for the above 200-object predicated query.) (I nested another question here previously, which I now moved away).

    Read the article

  • Failed to save to data store: The operation couldn’t be completed. (Cocoa error 133020.)

    - by poslinski.net
    I am working on quite complex app with huge sync procedure beetwen iphone and web server. I have no troubles with adding records, until I run sync procedure in separete thread, and It will update data on serwer, and send them back to iphone. But after this procedure, inserting new data cause error, such as this: 2011-01-07 12:49:10.722 App[1987:207] Failed to save to data store: The operation couldn’t be completed. (Cocoa error 133020.) 2011-01-07 12:49:10.724 App[1987:207] { conflictList = ( "NSMergeConflict (0x5ac1ea0) for NSManagedObject (0x5a2d710) with objectID '0x5a27080 <x-coredata://E82E75ED-96DB-4CBF-9D15-9CC106AC0052/uzytkownicy/p10>' with oldVersion = 9 and newVersion = 21 and old object snapshot = {\n adres = \"<null>\";\n haslo = xxxxxxxxxxxxxxxxxxxxxx;\n \"id_uzytkownika\" = 3;\n imie = Jan;\n \"kod_jednorazowy\" = 0;\n komorka = \"<null>\";\n login = nowakjan;\n nazwisko = Nowak;\n pesel = 0;\n rodzaj = 2;\n \"stan_konta\" = 0;\n telefon = \"<null>\";\n \"uzytkownicy_uczniowie\" = \"<null>\";\n \"zmienna_losowa\" = 8G9e1;\n} and new cached row = {\n adres = \"<null>\";\n haslo = xxxxxxxxxxxxxxxxxxxxxx;\n \"id_uzytkownika\" = 3;\n imie = Jan;\n \"kod_jednorazowy\" = 0;\n komorka = \"<null>\";\n login = nowakjan;\n nazwisko = Nowak;\n pesel = 0;\n rodzaj = 2;\n \"stan_konta\" = 0;\n telefon = \"<null>\";\n \"uzytkownicy_uczniowie\" = \"<null>\";\n \"zmienna_losowa\" = 8G9e1;\n}", "NSMergeConflict (0xd266990) for NSManagedObject (0xcd05950) with objectID '0x5a453b0 <x-coredata://E82E75ED-96DB-4CBF-9D15-9CC106AC0052/uczniowie/p125>' with oldVersion = 5 and newVersion = 10 and old object snapshot = {\n adres = \"Warszawa; ul. Lwowska 32\";\n \"data_urodzenia\" = \"1997-02-01 23:00:00 +0000\";\n dysfunkcje = \"\";\n email = \"<null>\";\n frekwencja = 0;\n \"id_ucznia\" = 86;\n imie2 = Marian;\n \"imie_ucznia\" = \"S\\U0142awomir\";\n klasa = \"0x5a47820 <x-coredata://E82E75ED-96DB-4CBF-9D15-9CC106AC0052/zespoly/p9>\";\n komorka = \"<null>\";\n \"miejsce_urodzenia\" = Warszawa;\n \"nazwisko_ucznia\" = \"S\\U0142awek\";\n \"numer_ewidencyjny\" = 20;\n opiekun1 = \"Mariusz S\\U0142awek\";\n opiekun2 = \" \";\n pesel = 97020298919;\n plec = 1;\n telefon = 890000002;\n \"uzytkownicy_uczniowie\" = \"<null>\";\n \"web_klasa\" = 50;\n} and new cached row = {\n adres = \"Warszawa; ul. Lwowska 32\";\n \"data_urodzenia\" = \"1997-02-01 23:00:00 +0000\";\n dysfunkcje = \"\";\n email = \"<null>\";\n frekwencja = 0;\n \"id_ucznia\" = 86;\n imie2 = Marian;\n \"imie_ucznia\" = \"S\\U0142awomir\";\n klasa = \"0x5a8e7c0 <x-coredata://E82E75ED-96DB-4CBF-9D15-9CC106AC0052/zespoly/p9>\";\n komorka = \"<null>\";\n \"miejsce_urodzenia\" = Warszawa;\n \"nazwisko_ucznia\" = \"S\\U0142awek\";\n \"numer_ewidencyjny\" = 20;\n opiekun1 = \"Mariusz S\\U0142awek\";\n opiekun2 = \" \";\n pesel = 97020298919;\n plec = 1;\n telefon = 890000002;\n \"uzytkownicy_uczniowie\" = \"<null>\";\n \"web_klasa\" = 50;\n}", "NSMergeConflict (0xd2669b0) for NSManagedObject (0x5a44480) with objectID '0x5a47830 <x-coredata://E82E75ED-96DB-4CBF-9D15-9CC106AC0052/przedmioty/p12>' with oldVersion = 7 and newVersion = 15 and old object snapshot = {\n \"id_przedmiotu\" = 1;\n \"nazwa_przedmiotu\" = Historia;\n \"skrot_nazwy\" = Hist;\n} and new cached row = {\n \"id_przedmiotu\" = 1;\n \"nazwa_przedmiotu\" = Historia;\n \"skrot_nazwy\" = Hist;\n}" ); } I've been looking for any solution but without luck. Thank You in advance for any usefull help.

    Read the article

  • NSMutableObject from existing custom class

    - by A.S.
    Hello there. I have an existing class that has methods to deserialise from XML in my code. Now I need to create correct CoreData model from that class. It's objects will be created not only from CoreData storage but also by deserializing XML (somehow like instance->title = [[NSString stringWithUTF8String: (const char *)subNode->children->content] retain; ) without saving to CoreData, and sometimes I need to save it. What is the correct steps to modify existing class to do that except of adding CoreData framework and making my class an NSManagedObject instead of NSObject? Class sample: @interface TSTSong : NSManagedObject<NTSerializableObject> { NSString *identifier; NSString *title; float length; NSURL *previewURL; NSString *author; NSURL *coverURL; NSString *appStoreId; BOOL isPurchased; NSURL *bannerURL; NSDecimalNumber *priceValue; NSLocale *priceLocale; } P.S. I'm noob, so I'f I'm doing smth. wrong - please let me know. Sorry for my english.

    Read the article

  • UIImage Rotation

    - by Kamchatka
    I display an image in a UIImageView (within a UIScrollView) which is also stored in CoreData. In the interface, I want the user to be able to rotate the picture by 90 degrees. I also want it to be saved in CoreData. What should I rotate in the display? the scrollview, the uiimageview or the image itself? (If possible I would like the rotation to be animated) But then I also have to save the picture to CoreData. I thought about changing the image orientation but this property is readonly.

    Read the article

  • iPhone App Crashes when merging managed object contexts

    - by DVG
    Short Version: Using two managed object contexts, and while the context is saving to the store the application bombs when I attempt to merge the two contexts and reload the table view. Long Version: Okay, so my application is set up as thus. 3 view controllers, all table views. Platforms View Controller - Games View Controller (Predicated upon platform selection) - Add Game View Controller I ran into a problem when Games View Controller was bombing when adding a new entry to the context, because the fetched results contorller wanted to update the view for something that didn't match the predicate. As a solution, I rebuilt the Add Controller to use a second NSManagedObject Context, called adding context, following the design pattern in the Core Data Books example. My Games List View Controller is a delegate for the add controller, to handle all the saving, so my addButtonPressed method looks like this - (IBAction) addButtonPressed: (id) sender { AddGameTableViewController *addGameVC = [[AddGameTableViewController alloc] initWithNibName:@"AddGameTableViewController" bundle:nil]; NSManagedObjectContext *aAddingContext = [[NSManagedObjectContext alloc] init]; self.addingContext = aAddingContext; [aAddingContext release]; [addingContext setPersistentStoreCoordinator:[[gameResultsController managedObjectContext] persistentStoreCoordinator]]; addGameVC.context = addingContext; addGameVC.delegate = self; addGameVC.newGame = (Game *)[NSEntityDescription insertNewObjectForEntityForName:@"Game" inManagedObjectContext:addingContext]; UINavigationController *addNavCon = [[UINavigationController alloc] initWithRootViewController:addGameVC]; [self presentModalViewController:addNavCon animated:YES]; [addGameVC release]; [addNavCon release]; } There is also a delegate method which handles the saving. This all works swimmingly. The issue is getting the table view controller in the GameListViewController to update itself. Per the example, an observer is added to watch for the second context to be saved, and then to merge the addingContext with the primary one. So I have: - (void)addViewController:(AddGameTableViewController *)controller didFinishWithSave:(BOOL)save { if (save) { NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter]; [dnc addObserver:self selector:@selector(addControllerContextDidSave:) name:NSManagedObjectContextDidSaveNotification object:addingContext]; //snip! Context Save Code [dnc removeObserver:self name:NSManagedObjectContextDidSaveNotification object:addingContext]; } self.addingContext = nil; [self dismissModalViewControllerAnimated:YES]; } - (void)addControllerContextDidSave:(NSNotification*)saveNotification { NSManagedObjectContext *myContext = [gameResultsController managedObjectContext]; [myContext mergeChangesFromContextDidSaveNotification:saveNotification]; } So now, what happens is after save is pressed, the application hangs for a moment and then crashes. The save is processed, as the new game is present when I relaunch the application, and the application seems to be flowing as appropriate, but it bombs out for reasons that are beyond my understanding. NSLog of the saveNotification spits out this: NSConcreteNotification 0x3b557f0 {name = NSManagingContextDidSaveChangesNotification; object = <NSManagedObjectContext: 0x3b4bb90>; userInfo = { inserted = {( <Game: 0x3b4f510> (entity: Game; id: 0x3b614e0 <x-coredata://13168366-B8E7-41C8-B384-BAF14A5E08D9/Game/p2> ; data: { name = "Final Fantasy XIII"; platform = 0x3b66910 <x-coredata://13168366-B8E7-41C8-B384-BAF14A5E08D9/Platform/p20>; }) )}; updated = {( <Platform: 0x3b67650> (entity: Platform; id: 0x3b66910 <x-coredata://13168366-B8E7-41C8-B384-BAF14A5E08D9/Platform/p20> ; data: { games = ( 0x3b614e0 <x-coredata://13168366-B8E7-41C8-B384-BAF14A5E08D9/Game/p2>, 0x603a530 <x-coredata://13168366-B8E7-41C8-B384-BAF14A5E08D9/Game/p1> ); name = "Xbox 360"; }) )}; }} I've tried both a simple [self.tableView reloadData]; and the more complicated multi-method table updating structure in the Core Data Books example. Both produce the same result.

    Read the article

  • Passing a ManagedObjectContext to a second view

    - by amo
    I'm writing my first iPhone/Cocoa app. It has two table views inside a navigation view. When you touch a row in the first table view, you are taken to the second table view. I would like the second view to display records from the CoreData entities related to the row you touched in the first view. I have the CoreData data showing up fine in the first table view. You can touch a row and go to the second table view. I'm able to pass info from the selected object from the first to the second view. But I cannot get the second view to do its own CoreData fetching. For the life of me I cannot get the managedObjectContext object to pass to the second view controller. I don't want to do the lookups in the first view and pass a dictionary because I want to be able to use a search field to refine results in the second view, as well as insert new entries to the CoreData data from there. Here's the function that transitions from the first to the second view. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Navigation logic may go here -- for example, create and push another view controller. NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath]; SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondView" bundle:nil]; secondViewController.tName = [[selectedObject valueForKey:@"name"] description]; secondViewController.managedObjectContext = [self managedObjectContext]; [self.navigationController pushViewController:secondViewController animated:YES]; [secondViewController release]; } And this is the function inside SecondViewController that crashes: - (void)viewDidLoad { [super viewDidLoad]; self.title = tName; NSError *error; if (![[self fetchedResultsController] performFetch:&error]) { // <-- crashes here // Handle the error... } } - (NSFetchedResultsController *)fetchedResultsController { if (fetchedResultsController != nil) { return fetchedResultsController; } /* Set up the fetched results controller. */ // Create the fetch request for the entity. NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; // Edit the entity name as appropriate. // **** crashes on the next line because managedObjectContext == 0x0 NSEntityDescription *entity = [NSEntityDescription entityForName:@"SecondEntity" inManagedObjectContext:managedObjectContext]; [fetchRequest setEntity:entity]; // <snip> ... more code here from Apple template, never gets executed because of the crashing return fetchedResultsController; } Any ideas on what I am doing wrong here? managedObjectContext is a retained property. UPDATE: I inserted a NSLog([[managedObjectContext registeredObjects] description]); in viewDidLoad and it appears managedObjectContext is being passed just fine. Still crashing, though. Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'SecondEntity''

    Read the article

  • exc_bad_access on insertNewObjectForEntityForName:inManagedObjectContext

    - by matthewc
    I have a garbage collected Cocoa application built on 10.5 frameworks. In an NSOperation In a loop I am quickly creating hundreds of NSManagedObjects. Frequently the creation of those NSManagedObejcts will crash with a exc_bad_access error. for (offsetCount; offsetCount < [parsedData count]; offsetCount++) { NSManagedObject *child = [NSEntityDescription insertNewObjectForEntityForName:@"Thread" inManagedObjectContext:[self moc]]; Thumbnail *thumb = [Thumbnail insertInManagedObjectContext:[self moc]]; Image *image = [Image insertInManagedObjectContext:[self moc]]; ... } Thumbnail and Image are both subclasses of NSManagedObject generated with mogenerator. insertInManagedObjectContext: looks like NSParameterAssert(moc_); return [NSEntityDescription insertNewObjectForEntityForName:@"Thumbnail" inManagedObjectContext:moc_]; NSParameterAssert(moc_); return [NSEntityDescription insertNewObjectForEntityForName:@"Image" inManagedObjectContext:moc_]; The NSManagedObjectContext returned by [self moc] is created for the NSOperation with NSPersistentStoreCoordinator *coord = [(MyApp_AppDelegate *)[[NSApplication sharedApplication] delegate] persistentStoreCoordinator]; self.moc = [[NSManagedObjectContext alloc] init]; [self.moc setPersistentStoreCoordinator:coord]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contextDidSave:) name:NSManagedObjectContextDidSaveNotification object:self.moc]; [self.moc setMergePolicy:NSMergeByPropertyObjectTrumpMergePolicy]; [self.moc setUndoManager:nil]; [self.moc setRetainsRegisteredObjects:YES]; moc is defined as (nonatomic, retain) and synthesized. As far as I can tell it, the persistent store and my appDelegate have no reason to be and are not being garbage collected. The stack trace looks like Thread 2 Crashed: Dispatch queue: com.apple.root.default-priority 0 libauto.dylib 0x00007fff82d63600 auto_zone_root_write_barrier + 688 1 libobjc.A.dylib 0x00007fff826f963b objc_assign_strongCast_gc + 59 2 com.apple.CoreFoundation 0x00007fff88677068 __CFBasicHashAddValue + 504 3 com.apple.CoreFoundation 0x00007fff88676d2f CFBasicHashAddValue + 191 4 com.apple.CoreData 0x00007fff82bdee5e -[NSManagedObjectContext(_NSInternalAdditions) _insertObjectWithGlobalID:globalID:] + 190 5 com.apple.CoreData 0x00007fff82bded24 -[NSManagedObjectContext insertObject:] + 148 6 com.apple.CoreData 0x00007fff82bbd75c -[NSManagedObject initWithEntity:insertIntoManagedObjectContext:] + 716 7 com.apple.CoreData 0x00007fff82bdf075 +[NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext:] + 101 8 com.yourcompany.MyApp 0x000000010002c7a7 +[_Thumbnail insertInManagedObjectContext:] + 256 (_Thumbnail.m:14) 9 com.yourcompany.MyApp 0x000000010002672d -[ThreadParse main] + 10345 (B4ChanThreadParse.m:174) 10 com.apple.Foundation 0x00007fff85ee807e -[__NSOperationInternal start] + 698 11 com.apple.Foundation 0x00007fff85ee7d23 ____startOperations_block_invoke_2 + 99 12 libSystem.B.dylib 0x00007fff812bece8 _dispatch_call_block_and_release + 15 13 libSystem.B.dylib 0x00007fff8129d279 _dispatch_worker_thread2 + 231 14 libSystem.B.dylib 0x00007fff8129cbb8 _pthread_wqthread + 353 15 libSystem.B.dylib 0x00007fff8129ca55 start_wqthread + 13 My app is crashing in other places with exc_bad_access but this is code that it happens most with. All of the stack traces look similar and have something to do with CFHash. Any help would be appreciated.

    Read the article

  • RestKit loadObjects

    - by Peter Lapisu
    iam using restKit, to send and receive data from server... iam getting back { "request":"globalUpdate", "updateRevision":2, "updatedObjects":{ "users":[ { id:"someid1", name:"somename" }, { id:"someid2", name:"somename2", } ] } } i want to use [[RKObjectManager sharedManager] loadObjectsAtResourcePath:nil usingBlock:^(RKObjectLoader * loader){)]; to load only objects inside updatedObjects into CoreData and request, updateRevision into NSDictionary so in loader.onDidLoadObjects = ^(NSArray *objects) { } the first object is the Dictionary and the later one are CoreData

    Read the article

  • Can't find momd file: Core Data problems

    - by thekevinscott
    Aw geez! I screwed something up! I'm a Core Data noob, working on my first iOS app. After much Stack Overflowing I'm using this code: NSString *path = [[NSBundle mainBundle] pathForResource:@"CoreData" ofType:@"momd"]; if (!path) { path = [[NSBundle mainBundle] pathForResource:@"CoreData" ofType:@"mom"]; } NSAssert(path != nil, @"Unable to find Resource in main bundle"); CoreData is the name of my app. I've tried to put in initial data into the app by finding the path to the sqlite file in my iPhone simulator, and then going and inserting into that sqlite file. But at some point, I moved the sqlite (thinking it would create a fresh copy), deleted the app from the simulator, and the sqlite file is gone. I'm not sure if I'm leaving out some part of the process (this was a few hours ago) but the end result is that everything is screwed up. How do I resubstantiate this sqlite / momd file? "Clean" and "Clean all targets" are grayed out. I'm happy to post the relevant code from my app that would help shed some light on this problem but there's tons of code relating to Core Data which I don't understand, so I'm not sure what part to post! Any help is greatly appreciated.

    Read the article

  • Conflict resolution for two-way sync

    - by K.Steff
    How do you manage two-way synchronization between a 'main' database server and many 'secondary' servers, in particular conflict resolution, assuming a connection is not always available? For example, I have an mobile app that uses CoreData as the 'database' on the iOS and I'd like to allow users to edit the contents without Internet connection. In the same time, this information is available on a website the devices will connect to. What do I do if/when the data on the two DB servers is in conflict? (I refer to CoreData as a DB server, though I am aware it is something slightly different.) Are there any general strategies for dealing with this sort of issue? These are the options I can think of: 1. Always use the client-side data as higher-priority 2. Same for server-side 3. Try to resolve conflicts by marking each field's edit timestamp and taking the latest edit Though I'm certain the 3rd option will open room for some devastating data corruption. I'm aware that the CAP theorem concerns this, but I only want eventual consistency, so it doesn't rule it out completely, right? Related question: Best practice patterns for two-way data synchronization. The second answer to this question says it probably can't be done.

    Read the article

  • How to convert an NSArray of NSManagedObjects to NSData

    - by carok
    Hi, I'm new to Objective C and was wondering if anyone can help me. I am using core data with a sqlite database to hold simple profile objects which have a name and a score attribute (both of which are of type NSString). What I want to do is fetch the profiles and store them in an NSData object, please see my code below: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"GamerProfile" inManagedObjectContext:managedObjectContext]; [fetchRequest setEntity:entity]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Name" ascending:YES]; NSArray *sortDecriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [fetchRequest setSortDescriptors:sortDecriptors]; [sortDescriptor release]; [sortDecriptors release]; NSError *error; NSArray *items = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error]; NSData *data = [NSKeyedArchiver archivedDataWithRootObject:items]; [self SendData:data]; [fetchRequest release]; When I run the code I'm getting the error "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[GamerProfile encodeWithCoder:]: unrecognized selector sent to instance 0x3f4b530'" I presume I have to add an encodeWithCoderClass to my core data NSManagedObject object (GamerProfile) but I'm not sure how to do this even after reading the documentation, My attempt at doing this is below. I'm not sure if I'm going along the right lines with this as get a warning stating "NSManagedObject" may not respond to '-encodeWithCoder'" I would really, really appreciate it if someone could point me in the right direction!! Thanks C Here is the code for my GamerProfile (CoreData NSManagedObject Object) with my attempt at adding an encodeWithCoder method... Header File #import <CoreData/CoreData.h> @interface GamerProfile : NSManagedObject <NSCoding> { } @property (nonatomic, retain) NSString * GamerScore; @property (nonatomic, retain) NSString * Name; - (void)encodeWithCoder:(NSCoder *)coder; @end Code File #import "GamerProfile.h" @implementation GamerProfile @dynamic GamerScore; @dynamic Name; - (void)encodeWithCoder:(NSCoder *)coder { [super encodeWithCoder:coder]; [coder encodeObject:GamerScore forKey:@"GamerScore"]; [coder encodeObject:Name forKey:@"Name"]; }

    Read the article

  • Building a list of favorites from Core Data

    - by Jim
    I'm building an app with two tabs. The first tab has a main tableview that connects to a detail view of the row. The second tab will display a tableView based on the user adding content to it by tapping a button on the detail view. My question is this. What is the correct design pattern to do this? Do I create a second ManagedObjectContext/ManagedObjectContextID then save that context to a new persistent store or can the MOC be saved to the existing store without affecting the original tableview? I've looked at CoreData Recipes and CoreData Books and neither deal with multiple stores although books does deal with multiple MOC's. Any reference would be great.

    Read the article

  • Wanting a simple overview on how to connect to a SQLite database in Cocoa/Objective-C

    - by Jesse
    Hi, everyone. I've been experimenting with Cocoa and Objective-C programming on the Mac for a few months now, and I am wanting to start developing applications that manage large amounts of data. The trouble is, I'm not really sure where to start with databases. I have a good background in Java programming with SQLite. I've read a bit about CoreData and I haven't been able to find any good resources for just manually connecting to the database. I'm looking for recommendations. Should I try CoreData, and if so, can anyone recommend a good tutorial for someone new to the language? Or, should I try to manually connect and query an SQLite database somehow, and, if so, any tutorials? Any help would be greatly appreciated! Thanks!

    Read the article

  • Core Data deleteObject: sets attributes to nil

    - by SG1
    I am implementing an undo/redo mechanism in my app. This works fine for lots of cases. However, I can't undo past deleteObject:. the object is correctly saved in the undo queue, and I get it back and reinsterted into the Core Data stack just fine when calling undo. The problem is that all it's attributes are getting set to nil when I delete it. I have an entity "Canvas" with a to-many relationship called "graphics" to a "Graphic" entity, which has its inverse set to "canvas". Deleting a Graphic, then inserting it back, doesn't work. Here's the code (the redo method is basically the same): - (void)deleteGraphic:(id)aGraphic { //NSLog(@"undo drawing"); //Prepare the undo/redo [self.undoManager beginUndoGrouping]; [self.undoManager setActionName:@"Delete Graphic"]; [[self.detailItem valueForKey:@"graphics"] removeObject:aGraphic]; [[self managedObjectContext] deleteObject:aGraphic]; //End undo/redo [self.undoManager registerUndoWithTarget:self selector:@selector(insertGraphic:) object:aGraphic]; [self.undoManager endUndoGrouping]; NSLog(@"graphics are %@", [self sortedGraphics]); //Update drawing [self.quartzView setNeedsDisplay]; } and here's the wierdness: Before delete: graphics are ( <NSManagedObject: 0x1cc3f0> (entity: Graphic; id: 0x1c05f0 <x-coredata:///Graphic/t840FE8AD-F2E7-4214-822F-7994FF93D4754> ; data: { canvas = 0x162b70 <x-coredata://A919979E-75AD-474D-9561-E0E8F3388718/Canvas/p20>; content = <62706c69 73743030 d4010203 04050609 0a582476 65727369 6f6e5424 746f7059 24617263 68697665 7258246f 626a6563 7473>; frameRect = nil; label = nil; order = 1; path = "(...not nil..)"; traits = "(...not nil..)"; type = Path; }) After redo: graphics are ( <NSManagedObject: 0x1cc3f0> (entity: Graphic; id: 0x1c05f0 <x-coredata:///Graphic/t840FE8AD-F2E7-4214-822F-7994FF93D4754> ; data: { canvas = nil; content = nil; frameRect = nil; label = nil; order = 0; path = nil; traits = nil; type = nil; }), You can see it's the same object, just totally bleached by Core Data. The relationship delete rouls apparently have nothing to do with it as I've set them to "No Action" in a test.

    Read the article

  • CORE DATA objectId changes constantly

    - by mongeta
    Hello, I have some data that I export into an XML file and put in a remote FTP Server. I have to identified each object with a unique attribute, it doesn't matter wich is, but must be persistent always = it can never change. I don't want to create a unique attribute, sequence, serial, etc. I'm using the objectID but every time I use it a get a new reference. I know that before the object has been saved, it has a 'temporal id', but once it's saved, it gets the definitive. I'm not seeing this, never. When I export, just fetch all data and loop, and always I get a new reference: NSURL *objectID = [[personalDataObject objectID] URIRepresentation]; // some of id received for the SAME OBJECT (no changes made, saved, ...) // 61993296 // 62194624 thanks, r. edit I was using %d instead of %@, now the returned data is: x-coredata://F46F3300-8FED-4876-B0BF-E4D2A9D80913/DataEntered/p1 x-coredata://F46F3300-8FED-4876-B0BF-E4D2A9D80913/DataEntered/p2

    Read the article

  • Self-relation messes up contents in fetching

    - by holographix
    Hi folks, I'm dealing with an annoying problem in core data I've got a table named Character, which is made as follows I'm filling the table in various steps: 1) fill the attributes of the table 2) fill the Character Relation (charRel) FYI charRel is defined as follows I'm feeding the contents by pulling the data from an xml, the feeding code is this curStr = [[NSMutableString stringWithString:[curStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]] retain]; NSLog(@"Parsing relation within these keys %@, in order to get'em associated",curStr); NSArray *chunks = [curStr componentsSeparatedByString: @","]; for( NSString *relId in chunks ) { NSLog(@"Associating %@ with id %@",[currentCharacter valueForKey:@"character_id"], relId); NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"character_id == %@", relId]; [request setEntity:[NSEntityDescription entityForName:@"Character" inManagedObjectContext:[self managedObjectContext] ]]; [request setPredicate:predicate]; NSerror *error = nil; NSArray *results = [[self managedObjectContext] executeFetchRequest:request error:&error]; // error handling code if(error != nil) { NSLog(@"[SYMBOL CORRELATION]: retrieving correlated symbol error: %@", [error localizedDescription]); } else if([results count] > 0) { Character *relatedChar = [results objectAtIndex:0]; // grab the first result in the stack, could be done better! [currentCharacter addCharRelObject:relatedChar]; //VICE VERSA RELATIONS NSArray *charRels = [relatedChar valueForKey:@"charRel"]; BOOL alreadyRelated = NO; for(Character *charRel in charRels) { if([[charRel valueForKey:@"character_id"] isEqual:[currentCharacter valueForKey:@"character_id"]]) { alreadyRelated = YES; break; } } if(!alreadyRelated) { NSLog(@"\n\t\trelating %@ with %@", [relatedChar valueForKey:@"character_id"], [currentCharacter valueForKey:@"character_id"]); [relatedChar addCharRelObject:currentCharacter]; } } else { NSLog(@"[SYMBOL CORRELATION]: related symbol was not found! ##SKIPPING-->"); } [request release]; } NSLog(@"\t\t### TOTAL OF REALTIONS FOR ID %@: %d\n%@", [currentCharacter valueForKey:@"character_id"], [[currentCharacter valueForKey:@"charRel"] count], currentCharacter); error = nil; /* SAVE THE CONTEXT */ if (![managedObjectContext save:&error]) { NSLog(@"Whoops, couldn't save the symbol record: %@", [error localizedDescription]); NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey]; if(detailedErrors != nil && [detailedErrors count] > 0) { for(NSError* detailedError in detailedErrors) { NSLog(@"\n################\t\tDetailedError: %@\n################", [detailedError userInfo]); } } else { NSLog(@" %@", [error userInfo]); } } at this point when I print out the values of the currentCharacter, everything looks perfect. every relation is in its place. in example in this log we can clearly see that this element has got 3 items in charRel: <Character: 0x5593af0> (entity: Character; id: 0x55938c0 <x-coredata://67288D50-D349-4B19-B7CB-F7AC4671AD61/Character/p86> ; data: { catRel = "<relationship fault: 0x9a29db0 'catRel'>"; charRel = ( "0x9a1f870 <x-coredata://67288D50-D349-4B19-B7CB-F7AC4671AD61/Character/p74>", "0x9a14bd0 <x-coredata://67288D50-D349-4B19-B7CB-F7AC4671AD61/Character/p109>", "0x558ba00 <x-coredata://67288D50-D349-4B19-B7CB-F7AC4671AD61/Character/p5>" ); "character_id" = 254; examplesRel = "<relationship fault: 0x9a29df0 'examplesRel'>"; meaning = "\n Left"; pinyin = "\n zu\U01d2"; "pronunciation_it" = "\n zu\U01d2"; strokenumber = 5; text = "\n \n <p>The most ancient form of this symbol"; unicodevalue = "\n \U5de6"; }) then when I'm in need of retrieving this item I perform an extraction, like this: // at first I get the single Character record NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSError *error; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"character_id == %@", self.char_id ]; [request setEntity:[NSEntityDescription entityForName:@"Character" inManagedObjectContext:_context ]]; [request setPredicate:predicate]; NSArray *fetchedObjs = [_context executeFetchRequest:request error:&error]; when, for instance, I print out in NSLog the contents of charRel NSArray *correlations = [singleCharacter valueForKey:@"charRel"]; NSLog(@"CHARACTER OBJECT \n%@", correlations); I get this Relationship fault for (<NSRelationshipDescription: 0x5568520>), name charRel, isOptional 1, isTransient 0, entity Character, renamingIdentifier charRel, validation predicates (), warnings (), versionHashModifier (null), destination entity Character, inverseRelationship (null), minCount 1, maxCount 99 on 0x6937f00 hope that I made myself clear. this thing is driving me insane, I've googled all over world, but I couldn't find a solution (and this make me think to as issue related to bad coding somehow :P). thank you in advance guys. k

    Read the article

  • Accessing elements from an array in objective c

    - by James
    I am trying to access individual elements of my array. This is an example of the contents of the array i am trying to access. <City: 0x4b77fd0> (entity: Spot; id: 0x4b7e580 <x-coredata://D902D50B-C945-42E2-8F71-EDB62222C0A7/Spot/p5> ; data: { CityToProvince = 0x4b7dbd0 <x-coredata://D902D50B-C945-42E2-8F71-EDB62222C0A7/County/p15>; Description = "Friend"; Email = "[email protected]"; Age = 21; Name = "Adam"; Phone = "+44175240"; }), The elements i am trying to access are Name, Phone, etc ... How would i go about doing this?

    Read the article

  • iPhone, how to dyanmic create new entity (table) via core data model?

    - by Robin
    as topic, I just want create new Entity(table) in sqlite , my code as follows: +(BOOL)CreateDataSet:(NSManagedObjectModel *) model attributes:(NSDictionary*)attributes entityName:(NSString*) entityName { NSEntityDescription *entityDef = [[NSEntityDescription alloc] init]; [entityDef setName:entityName]; [entityDef setManagedObjectClassName:entityName]; [model setEntities:[NSArray arrayWithObject:entityDef]]; //@step NSArray *properties = [CoreDataHelper CreateAttributes:attributes]; [entityDef setProperties:properties]; [entityDef release]; return TRUE; } but it throw errors: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Can't modify an immutable model.' * Call stack at first throw: ( 0 CoreFoundation 0x01c5abe9 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x01daf5c2 objc_exception_throw + 47 2 CoreData 0x0152634a -[NSManagedObjectModel(_NSInternalMethods) _throwIfNotEditable] + 106 3 CoreData 0x01526904 -[NSManagedObjectModel setEntities:] + 36 .... that seem show the model is read only..... anyone can help on this problem? thanks

    Read the article

  • Core Data not-reverse relationship subquery

    - by user561485
    Hi, I have the following entities in CoreData: Village - villageID Bookmark - (relation) village There are multiple villages with each an unique villageID. I have a entity Bookmark which only has a relation to a Village entity; it isn't possible to make a reverse relation. Now I would like to get the village entities where there exists a Bookmark relation. I've red something about subqueries, but I can't get it right for this situation. It must be something like: Village.villageID IN (Bookmark.village.villageID) It isn't possible to get first all the Bookmarks and then loop to get all the Villages, because of the design of the framework. Can this be done in CoreData (I presume the answer is "Yes, of course!") and how?

    Read the article

  • Implementing Autocompletion in iPhone UITextField for contacts in address book

    - by nacho4d
    Hi, I would like to have a UITextField or UITextView in where as I do some input, alternatives will appear something similar to when you type an address in Mail Application, alternatives appear down and is possible tap them so get a better input user interface.(since there is no need to type the complete word or address or phone number) I do know how to fetch data from Address Book framework, also how to input text in UITextField/UITextView and its delegates but I don't know what kind of structure to use for fetching and showing data as the user do his/her input. I know basic CoreData if this matters, I hope I can get some help. UPDATE (2010/3/10): I don't have problem make a native-like GUI but I am asking about the algorithm, does any body knows what kind algorithm is best for this thing? maybe some binary tree? Or should I just fetch data from coredata everytime? Thanks Ignacio UPDATE (2010/03/28): I've been very busy these days, so I have not tried UISearchResults but it seems fine to me. BUT I wonder was there a necessity of deletion of the wining answer? I don't think is fair my reputation went down and couldn't see the winning answer. ;(

    Read the article

  • Backwards compatibility when using Core Data

    - by Alex
    Could anybody shed some light as to why is my app crashing with the following error on iPhone OS 2.2.1 dyld: Symbol not found: _OBJC_CLASS_$_NSPredicate Referenced from: /var/mobile/Applications/456F243F-468A-4969-9BB7-A4DF993AE89C/AppName.app/AppName Expected in: /System/Library/Frameworks/Foundation.framework/Foundation I have weak linked CoreData.framework, and have the Base SDK set to 3.0 and Deployment Target set to SDK 2.2 The app already uses other 3.0 features when available and I did not have any problems with those. But apparently the backward-compatibility methods used for other features do not work with Core Data. The app crashes before app delegate's applicationDidFinishLaunching gets called. Here's the debugger log: [Session started at 2010-05-25 20:17:03 -0400.] GNU gdb 6.3.50-20050815 (Apple version gdb-1119) (Thu May 14 05:35:37 UTC 2009) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "--host=i386-apple-darwin --target=arm-apple-darwin".tty /dev/ttys001 Loading program into debugger… sharedlibrary apply-load-rules all warning: Unable to read symbols from "MessageUI" (not yet mapped into memory). warning: Unable to read symbols from "CoreData" (not yet mapped into memory). Program loaded. target remote-mobile /tmp/.XcodeGDBRemote-12038-42 Switching to remote-macosx protocol mem 0x1000 0x3fffffff cache mem 0x40000000 0xffffffff none mem 0x00000000 0x0fff none run Running… [Switching to thread 10755] [Switching to thread 10755] Re-enabling shared library breakpoint 1 Re-enabling shared library breakpoint 2 Re-enabling shared library breakpoint 3 Re-enabling shared library breakpoint 4 Re-enabling shared library breakpoint 5 (gdb) continue warning: Unable to read symbols for ""/Users/alex/iPhone Projects/AppName/build/Debug-iphoneos"/AppName.app/AppName" (file not found). dyld: Symbol not found: _OBJC_CLASS_$_NSPredicate Referenced from: /var/mobile/Applications/456F243F-468A-4969-9BB7-A4DF993AE89C/AppName.app/AppName Expected in: /System/Library/Frameworks/Foundation.framework/Foundation (gdb)

    Read the article

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