我想知道是否有可能(以及如何)在Objective-C中提供如下内容的类:
Person.Select(@"Name").OrderAsc(@"Name").Where(@"Id").EqualTo(1).And(@"Id").NotEqualTo(2).Load<Array>
对于我正在做的项目来说,这可能非常方便.
我喜欢Django&;Subsonic的这种编码方式.
我想知道是否有可能(以及如何)在Objective-C中提供如下内容的类:
Person.Select(@"Name").OrderAsc(@"Name").Where(@"Id").EqualTo(1).And(@"Id").NotEqualTo(2).Load<Array>
对于我正在做的项目来说,这可能非常方便.
我喜欢Django&;Subsonic的这种编码方式.
简而言之,Objective-C没有类似功能LinQ,但是您可以在一个包装类中混合使用SQLite、NSPredicate和CoreData调用来伪造它.你可能会对core data guide、predicate guide和this example code感兴趣.
从上面的谓词指南中可以看出:
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Employee"
inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
// assume salaryLimit defined as an NSNumber variable
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"salary > %@", salaryLimit];
[request setPredicate:predicate];
NSError *error = nil;
NSArray *array = [managedObjectContext executeFetchRequest:request error:&error];