Getting started with your EDIT2 and Edit3, the following answer will help you. Assume your id field as NSNumber having unsignedInt as an identifier.
1) Retrieve all entries for the corresponding object.
NSError *error = nil; NSArray *array = [self fetchAllFileEntity:&error];
2) Find the maximum number belonging to this result.
NSNumber *maxValue = nil; if (array) maxValue = [array valueForKeyPath:@"@max.uniqueId.unsignedIntegerValue"]; else maxValue = [NSNumber numberWithUnsignedInteger:0];
3) Assign maxValue + 1 to your new object
entity.uniqueId = [NSNumber numberWithUnsignedInteger:maxValue.unsignedIntegerValue+1];
source share