Jase
Jase

Reputation: 1379

Why does NSFetchRequest not initialise?

I'm create an NSFetchRequest, and it fails to initialise (returns <uninitialized> in the debugger) when created as below.

let request: NSFetchRequest<NSFetchRequestResult> = EntityName.fetchRequest()

However, it works perfectly when created like this:

let request: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: "EntityName")

Can anyone tell me why it would work the bottom way but not the top? The top way functions perfectly in the other three classes that use it.

Upvotes: 1

Views: 146

Answers (1)

galrito
galrito

Reputation: 352

I've been having the same problem with calling NSManagedObject.fetchRequest() on the tests target, but I was able to fix it by calling it inside a block on managed object context's perform(_:) method, like so:

context.perform {
    let request = EntityType.fetchRequest()
    (...)
}

Upvotes: 1

Related Questions