在Objective-C中是否有类似于LINQ的东西? [英] Is there something similar to LINQ in Objective-C?
本文介绍了在Objective-C中是否有类似于LINQ的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可能(以及如何)在Objective-C中提供类似以下的类:
I wonder if it is possible (and how) to provide a class in Objective-C with something like:
Person.Select(@"Name").OrderAsc(@"Name").Where(@"Id").EqualTo(1).And(@"Id").NotEqualTo(2).Load<Array>
这对于我正在做的项目非常方便。
That could be very handy for a project I'm doing.
我喜欢这种Django& SubSonic。
I like this way of coding present in Django & SubSonic.
推荐答案
简短的回答是,没有一个等价于Linq的Objective-C,但你可以混合SQLite,NSPredicate和CoreData调用在根据您的喜好的包装类中。您可能会对核心数据指南感兴趣, 谓词指南和此示例代码。
The short answer is that there is not an equivalent to Linq for Objective-C but you can fake it with a mix of SQLite, NSPredicate and CoreData calls in a wrapper class shaped to your liking. You'd probably be interested in the core data guide, the predicate guide, and 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];
这篇关于在Objective-C中是否有类似于LINQ的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文