Swift5 CoreStore CoreStore.fetchAll() 抛出错误

Swift5 CoreStore CoreStore.fetchAll() throws error

我正在使用 CoreStore CoreData 包装器和 Swift 5

import CoreStore

@objc(Post)
public class Post: NSManagedObject {

}

extension Post {

    @nonobjc public class func fetchRequest() -> NSFetchRequest<Post> {
        return NSFetchRequest<Post>(entityName: "Post")
    }

    @NSManaged public var detail: String?
    @NSManaged public var sync: Server?
    @NSManaged public var time: Time?

}

extension Post {
    static var allPosts: [Post] {
        var posts :  [Post] = []
        do {
            posts = try CoreStore.fetchAll(From<Post>().tweak({ [=11=].includesPendingChanges = false }))
        } catch {
            print(error)
        }
        return posts
    }
}

正在获取所有数据使用。

let posts = Post.allPosts

低于错误。

⚠️ [CoreStore: Error] From.swift:155 applyToFetchRequest(_:context:applyAffectedStores:) ↪︎ Attempted to perform a fetch but could not find any persistent store for the entity (CoreStore.CoreStoreError) .persistentStoreNotFound ( .errorDomain = "com.corestore.error"; .errorCode = 8; .entity = Post; )

解决使用获取数据到主线程。

DispatchQueue.main.async { 
   let posts = Post.allPosts 
}