core-data

Core data edit function

杀马特。学长 韩版系。学妹 提交于 2021-01-28 09:30:35
问题 I already have a tableView with data in it. IF you tap a cell/row it pushes to an edit type of view. Is there anyway to edit core data's data other than: By edit, i mean i already have data inserted into my context. I have loaded my data into my view, the user can change the existing data, and re save it. .h //Below is the entity/entity's class name 'Amm' Amm *amm; .m -(IBAction)save { [self.amm setValue:self.nameField.text forKey:@"name"]; [self.amm setValue:self.nicknameField.text forKey:@

Core data edit function

谁说胖子不能爱 提交于 2021-01-28 09:23:41
问题 I already have a tableView with data in it. IF you tap a cell/row it pushes to an edit type of view. Is there anyway to edit core data's data other than: By edit, i mean i already have data inserted into my context. I have loaded my data into my view, the user can change the existing data, and re save it. .h //Below is the entity/entity's class name 'Amm' Amm *amm; .m -(IBAction)save { [self.amm setValue:self.nameField.text forKey:@"name"]; [self.amm setValue:self.nicknameField.text forKey:@

Swift 4 CoreData NSFetchRequest: sum over computed variable

那年仲夏 提交于 2021-01-28 08:50:41
问题 I'm using CoreData for persistence and would like to use a NSFetchRequest with an NSExpression(forFunction: "sum:" ...). I have three Entities Entity A: name: String value: Int64 Entity B: name: String Entity C: relationship1: A relationship2: B value: Int64 I have a separate Entity for a relationship between an A- and an B-Entity, because a relationship also has an Int64 Value. I guess this is the easiest solution not to sum up one attribute of a given set of Cs (using a NSPredicate to

Does adding a new independent entity in Core Data require model versioning?

心已入冬 提交于 2021-01-28 04:47:41
问题 I want to add a new Core Data Entity in my project. Do I need to add a new core-data Model Version for this or it will work within existing version? The entity is independent and it will have no relation with other previously defined entities. 回答1: Indeed, it requires adding a new model version. However, adding a new entity can be handled by a lightweight migration, so at least you don't have to create a mapping model/write custom migration code. UPDATE: From the article about lightweight

iOS core data “joining” two “tables”

不羁岁月 提交于 2021-01-28 04:01:20
问题 I have to Entity in core data: GAMES and PLAYERS GAMES - look like this (simplified): board userid PLAYERS userid name PLAYERS is unique I need to select GAMES and add the PLAYERS.name column to this result. I have set up all core data and relationships, and can select from the "tables" and put it in a array and in a Tableview. NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"GAMES" inManagedObjectContext:context]

iOS core data “joining” two “tables”

╄→гoц情女王★ 提交于 2021-01-28 03:45:52
问题 I have to Entity in core data: GAMES and PLAYERS GAMES - look like this (simplified): board userid PLAYERS userid name PLAYERS is unique I need to select GAMES and add the PLAYERS.name column to this result. I have set up all core data and relationships, and can select from the "tables" and put it in a array and in a Tableview. NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"GAMES" inManagedObjectContext:context]

Is it possible to return NSManagedObjects as read-only in Core Data?

扶醉桌前 提交于 2021-01-28 01:50:41
问题 I'm using Core Data for caching of server data in a module that I'm writing and would like to be able to enforce that other parts of the application don't modify that data. Is is possible to mark either my instances of NSManagedObject, or the NSManagedObjectContext used to fetch them, as read-only? Since the context is accessible directly from the object, consumers are free to modify the object and call [obj.managedObjectContext save:&errror] . I've seen plenty of references to creating a

NSFetchedResultsController finds wrong number of objects

假装没事ソ 提交于 2021-01-27 19:04:30
问题 I'm seeing a situation where a NSFetchRequest returns a different number of objects depending on whether it's executed directly through the NSManagedObjectContext or as part of building a NSFetchedResultsController. Sample code: - (void)setupResultsController { NSError *error = nil; NSManagedObjectContext *ctx = [[DataManager sharedInstance] mainObjectContext]; // Create a fetch request and execute it directly NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription

Swift And CoreData With Custom Class As Transformable Object

≡放荡痞女 提交于 2021-01-27 14:37:15
问题 I am trying to use a custom class with swift and CoreData as a transformable object. I have been wasting hours trying to figure it out but cannot. I keep getting two errors: Property cannot be marked @NSManaged because its type cannot be represented in Objective-C and Property cannot be declared public because its type uses an internal type. Help is greatly appreciated. Thanks. I have a CoreData object named User. I also have an object named Site. I don't want the Site object to be a CoreData

Access FetchRequest from xcdatamodel in iOS

拟墨画扇 提交于 2021-01-27 06:31:40
问题 I'm using NSPersistentContainer to access my core data in iOS10 app and Xcode 8. Similar to Entity, I added a "UserFetchRequest" in my Coredata xcdatamodel. Below is the screen shot. How can I access the "UserFetchRequest" in the code? 回答1: Having given your fetch request a name in the Data Model Inspector on the right hand side: (in my case named "randomFetch" where yours is "UserFetchRequest"), get the model from the persistentContainer: let model = persistentContainer.managedObjectModel