core-data

fetchRequest is null when calling second time

允我心安 提交于 2021-02-11 15:55:28
问题 The code is let request: NSFetchRequest<NSFetchRequestResult> = Item.fetchRequest() print(request) Item is an entity of Core Data. The first execution is correct, but when execute it again error occurs Thread 12: EXC_BAD_ACCESS (code=1, address=0x0) . The following is logs: This is a similar question, but with Object C. It says that defining managedObjectContext in view controller directly instead of transferring it from AppDelegate can fix the bug. In my code, the managedObjectContext is in

iOS Core Data - Serious application error - attempt to insert nil - in less than 1%

柔情痞子 提交于 2021-02-11 12:33:38
问题 iOS Core Data - Serious application error - attempt to insert nil Hello, My app runs actualy stable, but in seldom cases it crashes with this error message... 2019-04-02 20:48:52.437172+0200 myAppName[4422:1595677] [error] error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. -[__NSCFSet addObject:]: attempt to insert nil with userInfo (null) CoreData: error:

Save multiple values per key in CoreData

拈花ヽ惹草 提交于 2021-02-10 23:28:40
问题 I'm currently looking into CoreData and need to save multiple values per key. In my case I just need to save a couple of strings, max 9, for a single Key in CoreData. Specifically, I want to save players for a game. My game object already contains relationship objects to these players, but I also want to save the Player names as records on the game object itself, as players can be deleted by my users and I want my game objects to be immune for that. I know in Cloudkit you can set the value of

Initializing CoreData in macOS

跟風遠走 提交于 2021-02-10 19:54:30
问题 In Cocoa, Storyboard's first view controller will call viewDidLoad (on the first view controller) before AppDelegate 's applicationDidFinishLaunching is called. Since I am grabbing my NSManagedObjectContext in applicationDidFinishLaunching , I need to wait for applicationDidFinishLaunching before loading my data. In other words, in viewDidLoad , I don't yet have my NSManagedObjectContext . What I'm doing now: I'm adding an applicationDidFinishLaunching observer in my viewDidLoad , and load

Why does Core Data context object have to be passed via environment variable?

穿精又带淫゛_ 提交于 2021-02-10 18:10:36
问题 Inside SceneDelegate the context is passed via .environment(\.managedObjectContext, context) why cannot it be passed via View's property? What's the advantage of doing so? So instead of doing below let contentView = FlightsEnrouteView() .environment(\.managedObjectContext, context) We can pass the context via the View's initializer let contentView = FlightsEnrouteView(context: context) so inside FlightsEnrouteView should be, struct FlightsEnrouteView: View { var context:

iOS8.1 Core-Data Lightweight + Heavyweight Migration

拜拜、爱过 提交于 2021-02-10 09:42:49
问题 I have Version 1 of my core-data database. (Reduced example) I make some changes to the model, making V2. This involves creating a new entity with type attribute plus a few others. The type attribute is the link to the plate entity. The new version of my app is released and the data migrates ok as this is lightweight. For my own reasons at the time, I did not create a relationship at this time. Sometime later I decide to do some bigger changes to the structure, creating new entities

iOS8.1 Core-Data Lightweight + Heavyweight Migration

a 夏天 提交于 2021-02-10 09:41:39
问题 I have Version 1 of my core-data database. (Reduced example) I make some changes to the model, making V2. This involves creating a new entity with type attribute plus a few others. The type attribute is the link to the plate entity. The new version of my app is released and the data migrates ok as this is lightweight. For my own reasons at the time, I did not create a relationship at this time. Sometime later I decide to do some bigger changes to the structure, creating new entities

Update data in CoreData and its value in a view

故事扮演 提交于 2021-02-10 06:43:34
问题 I am new to developing in Swift and CoreData. I've been struggling with the following code which displays a view with some information on a student which is stored with CoreData. The button "Ask question" which is displayed in the view updates student.questionAskedClass but the view does not updates its value. The value is clearly updated internally because if I relaunch the application, I can see that the value has been updated. But I would like to see it updated live. Thanks for your help,

How to get the size of data present in coredata store?

你说的曾经没有我的故事 提交于 2021-02-08 12:27:12
问题 How to get the total memory size in bytes of data present in core data store.And How to get the memory size for particular rows of data. 回答1: On iOS 7 and above, older answers don't work anymore for SQLite-backed persistent stores, because of SQLite journal files. For each persistent store file you need to get the size of the SQLite file itself (e.g. Foo.sqlite ) and the sizes of the journal files (e.g. Foo.sqlite-wal and Foo.sqlite-shm ) and add the sizes to get the total. This is really

core data with duplicate entity values in swift

半世苍凉 提交于 2021-02-08 11:30:47
问题 I am parsing some data from Json and saved into the coredata,after fetching core data showing into the tableview working fine, tableview is show all the value in repeatedly how can avoid the repeated values I tried many ways but not find way Json format { "contacts": [ { "id": "c200", "name": "Ravi Tamada", "email": "ravi@gmail.com", "address": "xx-xx-xxxx,x - street, x - country", "gender" : "male", "phone": { "mobile": "+91 0000000000", "home": "00 000000", "office": "00 000000" } }, { "id"