Aren't the new Core Data requests meant to return the specified entity?

Hi

I was trying out the new generic API in XCode 8, and I expected this code to make my variable currencies be of type [Currency], where Currency is the class of an entity that I have defined in Core Data. But the type of currencies is NSPersistentStoreResult.

The Core Data talk in WWDC seems to suggest that generics meant no more type casting. What am I doing wrong here?

I am using the latest Xcode 8 beta from July 5.

TIA

Mark


        let context: NSManagedObjectContext = getDataStack().context
        let request = Currency.fetchRequest()
        let currencies = try context.execute(Currency.fetchRequest())

Replies

executeFetchRequest, not execute, to do what you want.

I have solved it with a bit of poking around on google.


The problem was that I wanted to use the generics. I was rewriting code that used a previous Swift library, to use the generics introduced at WWDC 2016. My app is not all compiling yet, but this compiles and tells my that currencies is of type [Currency], which is what I wanted.


        let context: NSManagedObjectContext = getDataStack().context
        let request = NSFetchRequest<Currency>()
        let currencies = try context.fetch(request)

Thanks for the reply, but I don't think that is part of the new Swift 3 library that uses generics. The code I have just added seems to be what I was after.