I have a method that returns an NSMutableArray of entities from my CoreData database. The entities look like this
@property (nonatomic, retain) NSNumber * iD;
@property (nonatomic, retain) NSString * number;
@property (nonatomic, retain) ManufacturerNumber *manufacturerNumber;
I need to create a unique array of manufacturerNumber entities based of the number NSString.
this is how my method that returns the current array with duplicates looks.
- (NSMutableArray *)readNumber
{
NSManagedObjectContext *context = [self managedObjectContext];
// Test listing all FailedBankInfos from the store
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"ManufacturerNumber" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSError *error;
NSMutableArray *manufacturerNumbersDictionaryArray = [[NSMutableArray alloc] init];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
for (ManufacturerNumber *manufacturerNumber in fetchedObjects) {
[manufacturerNumbersDictionaryArray addObject:manufacturerNumber];
}
return manufacturerNumbersDictionaryArray;
}
This returns an NSMutableArray including duplicates, and I'd like to remove the duplicates.
Update to question
I have now decided to edit the array when I go to display the values in my UITableview, below I explain what the array contains etc.
I have a NSMutableArray that contains the coredata entities described above, I would like to know how to create a NSSet of unique values from the NSMutablerArray based from the entities cNumber attribute.
This is how I have created the NSMutableArray
tableViewMArray = [NSMutableArray arrayWithArray:[cardManufacturerNumber.cNumbers allObjects]];
As you can see cardManufacturerNumber is a coredata object with a one to many relationship with cNumbers.
cNumbers has 3 attributes
- numString
- numID
- parentObj
I would like to know how to create a unique NSMutableArray based off cNumbers numString attribute.
The NSMutableArray should consisit of unique cNumbers coredata objects. not just numString strings as I need to know the other values.