Sean White
Sean White

Reputation: 11

swift 2 Core Data Predicate case insensitive search set in array

I have a subclass A with a one to many B relationship. I would like to search an attribute in B case. So i manage to do this but I don't know how to make it case insensitive.

Class A{
    @NSManaged var id:String?
    @NSManaged var relationshipToB: NSSet?
}

Class B{
    @NSManaged var someAttribute: String?
}

This works but it is case sensitive. how do I make it case insensitive? Where do i add the [c]?

let fetchRequest = NSFetchRequest(entityName: "A")
var predicates = [NSPredicate]()
predicates.append(NSPredicate(format:"ANY relationshipToB. someAttribute in  %@", arrayToSearch))
.
.
.

I tried adding the "[c]" in almost any position but no luck. Any one have an idea?

Thanks!

Upvotes: 1

Views: 880

Answers (2)

Bhavesh Patel
Bhavesh Patel

Reputation: 596

You can try this below code.

predicates.append(NSPredicate(format:"ANY mainText. someAttribute in [cd] %@", array))

Upvotes: 0

Jimmy James
Jimmy James

Reputation: 847

You can try this:

predicates.append(NSPredicate(format:"ANY relationshipToB. someAttribute in [c] %@", arrayToSearch))

Upvotes: 1

Related Questions