0

I want to fetch a result that doesn't have some same parameter.

like this.

Sample:

Obj1.title= @"1"
Obj2.title= @"3"
Obj3.title= @"3"
Obj4.title= @"3"
Obj5.title= @"4"

Result:

Obj1, Obj2, Obj5

Is it possible in NSFetchRequest?

2 Answers 2

1

Yes this can be done by setting the returnDitinctProperties on the fetchRequest:

request.returnsDistinctResults = YES;

For this to work, you also need to set which properties need to be fetched:

request.propertiesToFetch = @[@"title"];

Fore more details, see Apple's documentation: https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/CoreDataSnippets/Articles/fetchExpressions.html

Sign up to request clarification or add additional context in comments.

1 Comment

It was useful~ Thanks~
0

You can add all your Objects.title to an NSArray myArray, an then you can add the myArray to an NSSet to have an NSSet with unique titles.

NSSet *uniqueTitles = [NSSet setWithArray:myArray];

1 Comment

I want to fetch the Obj, not the title.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.