Every time I try to compile this, I get an error message:
Cannot convert value of type '[T]' to expected argument type '[_]'
I am not sure why this is happening, and I tried to find solutions, but did not find anything useful. Here is my code:
class FetchRequest <T: NSManagedObject>: NSFetchRequest<NSFetchRequestResult> { init(entity: NSEntityDescription) { super.init() self.entity = entity } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } typealias FetchResult = (success: Bool, objects: [T], error: NSError?) func fetch <T> (request: FetchRequest<T>, context: NSManagedObjectContext) -> FetchResult { do { let results = try context.fetch(request) return FetchResult(true, results as! [T], nil) } catch let error as NSError { return (false, [], error) } } }
EDIT:
I get an error on this line:
return FetchResult(true, results as! [T], nil)
source share