且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Objective-C中是否有类似于LINQ的东西?

更新时间:2023-11-28 23:29:52

简短的回答是,没有一个等价于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];