core-data

Core Data Group By Monthly and Sum

南楼画角 提交于 2020-01-15 11:36:22
问题 Is there any way to GROUP BY core data based on its month then SUM its properties? I have data like this ------------------------ date | amount ------------------------ 30-08-2017 | 124000000 28-10-2017 | 124000000 16-10-2017 | 124000000 14-12-2017 | 124000000 20-12-2017 | 124000000 ------------------------ I just need to show one latest year, so I created my fetch request like this NSDate *now = [NSDate date]; NSDate *oneYearAgo = [now addYears:-1]; NSEntityDescription *entity =

Getting thread errors when calling obtainPermanentIDsForObjects

独自空忆成欢 提交于 2020-01-15 10:43:31
问题 I'm creating a new NSManagedObject and inserting it into a context with concurrency type private queue (so it runs on a background thread). Right before I save, I call this: [appDelegate.backgroundMOC obtainPermanentIDsForObjects: [NSArray arrayWithObject:newObject] error:&error]; Then I save: [appDelegate.backgroundMOC save:&err]; However, I get a EXC_BAD_ACCESS crash. Looking at the stacktrace, I see: 0 semaphore_wait_trap 7-[NSManagedObjectContentSave:] I'm guessing the problematic line is

Not update Table after saving or updating Core data - Swift

风格不统一 提交于 2020-01-15 10:16:15
问题 I have bellow class for my CRUD in my project: class ProjectCoreDataStore: DegreesProtocol, DegreesStoreUtilityProtocol { // MARK: - Managed object contexts var mainManagedObjectContext: NSManagedObjectContext var privateManagedObjectContext: NSManagedObjectContext // MARK: - Object lifecycle init() { //let fileName: String = "PortalMDBApp.sqlite" let fileName: String = "MDB.sqlite" let fileManager:FileManager = FileManager.default let directory = fileManager.urls(for: .documentDirectory, in:

Not update Table after saving or updating Core data - Swift

送分小仙女□ 提交于 2020-01-15 10:16:08
问题 I have bellow class for my CRUD in my project: class ProjectCoreDataStore: DegreesProtocol, DegreesStoreUtilityProtocol { // MARK: - Managed object contexts var mainManagedObjectContext: NSManagedObjectContext var privateManagedObjectContext: NSManagedObjectContext // MARK: - Object lifecycle init() { //let fileName: String = "PortalMDBApp.sqlite" let fileName: String = "MDB.sqlite" let fileManager:FileManager = FileManager.default let directory = fileManager.urls(for: .documentDirectory, in:

Input a dynamic value into @FetchRequest, to fetch a single entity from core data in SwiftUI

自作多情 提交于 2020-01-15 10:14:46
问题 I saw same type of error but with different kind of code here, so I think it's better to ask a new question on this context. I have attempted to "find a specific entity" from core data by trying to pass a string variable (which use as a key to find that entity) called title into @FetchRequest . This is part of the code I have used struct AccountMainPage: View { //*** User input *** var title: String //*** Core data enviroment initialisation *** @Environment(\.presentationMode) var

Core data how update a record?

倖福魔咒の 提交于 2020-01-15 08:29:27
问题 I have some object that is image that is in relation with object user mani-to-one like that Image <<---> User. Now that i want to do, when the user is login i display a button to each images for add to favourites, when i click this button is run this code: User * user = [[UserController sharedInstance] currentUser]; Image * image = (Image*)[user.managedObjectContext objectWithID:[self.yacht objectID]]; yacht.whoLiked = user the problem is not i the same controller but in the Main Controller

subclassed NSManagedObject does not call description when NSLog'd

混江龙づ霸主 提交于 2020-01-15 06:11:21
问题 I have a data model which has two entities in a relationship of one to many. Each entity has a class that is subclassed from NSManagedObject. I get the relation set for the one entity and walk it casting each set member to the specific subclass as I enumerate the collection. When I do NSLog(@"My Entity: %@", myEntityInstance); It logs but does not call my subclass's method for: - (NSString*) description It does call if I send: NSLog(@"My Entity: %@", [myEntityInstance description]); Any ideas

Core Data 'File “Contents” couldn't be opened'

99封情书 提交于 2020-01-15 04:15:40
问题 I made the silly mistake and I accidentially touch my current Core Data model instead the new version one I just created. So I went to source control and reverted the changes inside the **.xcdatamodeld group. However I have now a zombie entry in the project structure inside this group (its the new version **.xcdatamodel I have created) that I can't open (message like in the title). Probably because reverting deleting the files but somehow the reference is still there. Just a little bit

Core Data 'File “Contents” couldn't be opened'

心已入冬 提交于 2020-01-15 04:12:07
问题 I made the silly mistake and I accidentially touch my current Core Data model instead the new version one I just created. So I went to source control and reverted the changes inside the **.xcdatamodeld group. However I have now a zombie entry in the project structure inside this group (its the new version **.xcdatamodel I have created) that I can't open (message like in the title). Probably because reverting deleting the files but somehow the reference is still there. Just a little bit

What's Core Data's .omo file? Is it required?

这一生的挚爱 提交于 2020-01-14 19:14:29
问题 When I compile Core Data model, I get .mom, .omo and versioninfo file. .mom looks like Managed Object Model file. And what's .omo file? I have no idea. Especially when I want to make a static lib for iOS, it's confusing should I embed the omo file too. And Xcode doesn't recognize the data model bundle. I have to bed them as file basis. What is the .omo file? 回答1: At WWDC this year I talked to the Core Data engineers in the labs and they told me that the .omo file is just an optimized version