mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
Could anyone guide me on how to make full use of CoreStore to setup, define and initialize the configuration of coreStore stack #168
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @evering7 on GitHub (Sep 11, 2017).
`class SourceFeed_CoreData: NSManagedObject {
@NSManaged var url: String
@NSManaged var fileName: String
} // class SourceFeed_CoreData: CoreStoreObject 2017.9.11
func prepareCoreDataStack() {
do {
try CoreStore.addStorageAndWait()
} catch {
printLog("error = (error.localizedDescription)")
}
}`
produce the following error when I debug the code. Could any one help me?
2017-09-11 20:26:21.781230+0800 iSpeak8[8362:2276713] PBItemCollectionServicer connection disconnected.
❗ [CoreStore: Fatal Error] BaseDataTransaction.swift:83 create
↪︎ Attempted to create an entity of type 'SourceFeed_CoreData', but a destination persistent store containing the entity type could not be found.
fatal error: file /Users/jianfeili/Documents/vip_iSpeaking/v_008/iSpeak8/Pods/CoreStore/Sources/BaseDataTransaction.swift, line 83
2017-09-11 20:27:09.681640+0800 iSpeak8[8362:2276628] fatal error: file /Users/jianfeili/Documents/vip_iSpeaking/v_008/iSpeak8/Pods/CoreStore/Sources/BaseDataTransaction.swift, line 83
@JohnEstropia commented on GitHub (Sep 11, 2017):
You are relying on the implicit creation of the
DataStackand theSQLiteStore, so this code will only work if and only if:*.xcdatamodeldfile is the same name as your app'sCFBundleNameSourceFeed_CoreDataentity in the "Default" configurationTo answer your question, please refer to the the README file which provides a complete example to setup both the
DataStackand theSQLiteStore: https://github.com/JohnEstropia/CoreStore#setting-up@evering7 commented on GitHub (Sep 12, 2017):
The focus of my problem is now on how to define the class for the entity. Could you guide me on how to correctly define the entity class and set the value of attributes. The following code would report error when building
@evering7 commented on GitHub (Sep 12, 2017):
I have partly solve my problem. I will explore the other aspects of the CoreStore. Now I temporarily don't need answer.
@evering7 commented on GitHub (Sep 12, 2017):
I delete xcdatamodel file, and use the full CoreStoreSchema grammar.
@JohnEstropia commented on GitHub (Sep 12, 2017):
Sorry for the late reply (Japan timezone). You may have found it already, but the setup for CoreStoreSchema is outlined here: https://github.com/JohnEstropia/CoreStore#type-safe-corestoreobjects
You can also find actual working code in the Demo app and the Unit Tests.
Let me know if you have other questions :)
@evering7 commented on GitHub (Sep 12, 2017):
I have write a function to get the data in CoreData to the memory variables. The function is just as below
I know such writing is not elegant. Could you help me on how to fetchAll and pass data into the sourceFeeds and running ok?
Thank you very much!
@JohnEstropia commented on GitHub (Sep 12, 2017):
Hmm there's a lot of things I'm worried about here but I'll try to comment on each separately.
transactionargument inside the transaction block to do anything inside that block. Always remember that the objects that are valid inside the transaction closure (background thread) and the completion closure (main thread) are in different worlds, so you need to fetch between them:@evering7 commented on GitHub (Sep 13, 2017):
Thank you any way. I have adopted the second solution of yours. All is OK now. My original thoughts is too complex. I use semaphore because I thought I should get the asynchronous functions get results synchronously. Thank you very much. The framework of yours is very powerful and easy to use.
@evering7 commented on GitHub (Sep 13, 2017):
Hi, John. The above code is running correctly in the morning at my home, but it can't work well in my office on the same MacBook Pro of mine. I have tested that "CoreStore.fetchCount" would lead to assert error in line 375 of value.swift. Though I have tested at the beginning of the function that the code is on the main thread.
@evering7 commented on GitHub (Sep 13, 2017):
So I have simulate the method 2 suggestion by you in the above. write the second version of this function as following
@evering7 commented on GitHub (Sep 13, 2017):
The above code is the third version of my function. but it still report assertion errors when debugging
@evering7 commented on GitHub (Sep 14, 2017):
I have found the GCD is not compatible with CoreStore. So I want to give up CoreStore and manually use CoreData
@JohnEstropia commented on GitHub (Sep 14, 2017):
That's not true though. CoreStore actually uses GCD a lot in its internals. Your issue is you are fighting with the queuing that CoreStore sets up for you by creating your own queues.
That said, CoreStore have methods for synchronous and asynchronous transactions (and even unsafe transactions) so it is possible to use your own queueing as well. In fact there are several people on the CoreStore slack group who does this. The issue is you are not using the right transactions for the queues you are using (for example, using asynchronousTransaction and blocking it with a semaphore).
The assertion failure you see above is a critical warning that you are accessing the object in the wrong queue. If you use Core Data manually and continue using objects like this, you won't get assertion errors but straight up crash your app, or worse, corrupt your data.
Of course you are free to use CoreStore or not, and there are libraries out there you may find better for you. But whatever path you take, my suggestion is for you to brush up first on concurrency concepts, especially in tandem with database access, because multithreading errors will always be a danger no matter what framework you are using.
I'm closing this issue, but feel free to continue the discussion :)