I'm using CoreStore
Wrapper of CoreData with 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({ $0.includesPendingChanges = false }))
} catch {
print(error)
}
return posts
}
}
Fetching all data using.
let posts = Post.allPosts
Getting below error.
⚠️ [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; )
Solve using fetching data into main thread.
DispatchQueue.main.async {
let posts = Post.allPosts
}