Alexander Khitev
Alexander Khitev

Reputation: 6851

NSPredicate equals nil in NSFetchRequest

I want to fetch object from Core Data using NSPredicate. I made it, but when I launch NSFetchRequest the NSPredicate equals nil shown in the console. I have the Xcode 6.4, Swift 1.2. I restarted Xcode but I get the same result. How can I make it?

func fetchRequest() -> NSFetchRequest {
    let fetchRequest = NSFetchRequest(entityName: "Car")
    let sortDescriptor = NSSortDescriptor(key: "personCar", ascending: true)
    fetchRequest.predicate = NSPredicate(format: "personRelationship.namePerson contains[c] %@", currentPerson)
    fetchRequest.fetchBatchSize = 50
    fetchRequest.sortDescriptors = [sortDescriptor]
    println(fetchRequest)
    return fetchRequest
}

The message from the console

<NSFetchRequest: 0x1700db040> (entity: Car; predicate: ((null)); sortDescriptors: ((
    "(personCar, ascending, compare:)"
)); batch size: 50; type: NSManagedObjectResultType; )

Upvotes: 0

Views: 771

Answers (1)

whyceewhite
whyceewhite

Reputation: 6425

Make sure that your fetchRequest.predicate value is set (i.e., is not nil).

The code in your post does show that the predicate value is assigned. However, when the NSFetchRequest.predicate attribute is not set then the println console message will display ((null)) for the predicate value.

Upvotes: 1

Related Questions