amazonwebservices/aws-sdk-for-ios — pull request #10 by duckmaestro (2012-09-30 00:02:23+00:00)
Title: Partial support for range keys in Core Data.

Modifications toward supporting range keys in the DynamoDB for Core Data. Tested changes include creating new entity instances that have range keys, requesting single items using hash+range, and requesting a range of results using a hash key, upper and lower bounds on range key, result limit, and sort direction.

Additional work may be needed in order to support:
- range key for proper uniqueness in -obtainPermanentIDsForObjects.
- Core Data Relationships based on range keys (we do not use Core Data relationships heavily in our project).

Example usage:

// Result variables.
NSArray* items = nil;
NSError* error = nil;

// Prepare context and fetch request.
id context = ...;
NSEntityDescription* entityDescription = ...;
NSFetchRequest* request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescription];

// Prepare range key upper and lower bounds.
NSDate* upperBound = [NSDate date];
NSDate* lowerBound = [NSDate dateWithTimeIntervalSince1970:0];

// Setup hash key and range key bounds in predicate.
NSPredicate* predicate =
[NSPredicate predicateWithFormat:@"myHashKey == %@ AND myRangeKey BETWEEN %@", userId, [NSArray arrayWithObjects: lowerBound, upperBound, nil]];
[request setPredicate:predicate];

// Set max results.
[request setFetchLimit:maxResults];

// Setup sort direction.
NSSortDescriptor* sort = [NSSortDescriptor sortDescriptorWithKey:@"timestamp" ascending:NO];
[request setSortDescriptors:[NSArray arrayWithObject:sort]];

// Execute request
items = [context executeFetchRequest:request error:&error];