Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ extension NSManagedObjectContext: Context {
return typedResults
}

public func count<T: Entity>(_ request: FetchRequest<T>) throws -> Int {
guard let entity = T.self as? NSManagedObject.Type else { throw StorageError.invalidType }
let fetchRequest: NSFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: entity.entityName)
fetchRequest.predicate = request.predicate
fetchRequest.fetchOffset = request.fetchOffset
fetchRequest.fetchLimit = request.fetchLimit
let result = try self.count(for: fetchRequest)
return result
}

public func insert<T: Entity>(_ entity: T) throws {}

public func new<T: Entity>() throws -> T {
Expand Down
1 change: 1 addition & 0 deletions SugarRecord/Source/Foundation/Protocols/Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Foundation
public protocol Context: Requestable {

func fetch<T: Entity>(_ request: FetchRequest<T>) throws -> [T]
func count<T: Entity>(_ request: FetchRequest<T>) throws -> Int
func insert<T: Entity>(_ entity: T) throws
func new<T: Entity>() throws -> T
func create<T: Entity>() throws -> T
Expand Down