Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用条件objective-c从NSMutable数组获取对象_Objective C_Arrays_Nsmutablearray - Fatal编程技术网

使用条件objective-c从NSMutable数组获取对象

使用条件objective-c从NSMutable数组获取对象,objective-c,arrays,nsmutablearray,Objective C,Arrays,Nsmutablearray,我想从数组中获取一些对象,其中包含一个对象属性满足条件的对象 就像c#一样 例如: NSMutablearray * coursesinfo ; 此数组包含30多个课程 课程是客体,其性质是最终的交易 我想学习所有课程,最终成绩

我想从数组中获取一些对象,其中包含一个对象属性满足条件的对象

就像c#一样

例如:

NSMutablearray * coursesinfo ;
此数组包含30多个课程

课程是客体,其性质是最终的交易

我想学习所有课程,最终成绩<100


我可以像c#一样在objective-c中这样做吗?以及如何使用?

最接近的是使用
-(NSArray*)过滤器使用谓词:(nspreditate*)谓词
NSArray的函数


链接到。

最接近的是使用
-(NSArray*)过滤器使用谓词:(nspreditate*)谓词
NSArray的函数


链接到。

where语句类似于在cocoa/cocoa touch中使用谓词。下面是一个示例,其中我有一个目录中的图像文件名数组,我正在查找基本文件名。方法返回一组通过特定测试的索引。NSEnumerationConcurrent利用并发队列来利用多个核心(如果存在)

NSIndexSet *indexSet=[allImageURLs indexesOfObjectsWithOptions:NSEnumerationConcurrent passingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
    BOOL match=NO;
    NSRange twoXRange=[((NSURL *)obj).absoluteString rangeOfString:@"@2x"];
    NSRange iPhoneRange=[((NSURL *)obj).absoluteString rangeOfString:@"~ipad"];
    if (twoXRange.location==NSNotFound && iPhoneRange.location==NSNotFound) {
        match=YES;
    }
    return  match;
}];

self.imageURLs=[allImageURLs objectsAtIndexes: indexSet];
对于您的特殊情况,我将执行以下操作:

NSIndexSet *theSet=[coursesinfo indexesOfObjectsWithOptions:NSEnumerationConcurrent passingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
    BOOL match=NO;

    if( obj.finalGrade<100 ){
       match=YES;
    }
    return match;
}];

NSArray *courses=[coursesinfo objectsAtIndexes: theSet];
NSIndexSet*theSet=[coursesinfo IndexeSofObjects选项:NSEnumerationConcurrent passingTest:^BOOL(id obj,nsu整数idx,BOOL*stop){
布尔匹配=否;

如果(obj.finalGradewhere语句类似于在cocoa/cocoa touch中使用谓词。下面是一个示例,其中我从目录中获取一个图像文件名数组,并查找基本文件名。indexesOfObjectsWithOptions:方法返回一组通过特定测试的索引。NSEnumerationConcurrent使用并发排队以利用多个核心(如果存在)

NSIndexSet *indexSet=[allImageURLs indexesOfObjectsWithOptions:NSEnumerationConcurrent passingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
    BOOL match=NO;
    NSRange twoXRange=[((NSURL *)obj).absoluteString rangeOfString:@"@2x"];
    NSRange iPhoneRange=[((NSURL *)obj).absoluteString rangeOfString:@"~ipad"];
    if (twoXRange.location==NSNotFound && iPhoneRange.location==NSNotFound) {
        match=YES;
    }
    return  match;
}];

self.imageURLs=[allImageURLs objectsAtIndexes: indexSet];
对于您的特殊情况,我将执行以下操作:

NSIndexSet *theSet=[coursesinfo indexesOfObjectsWithOptions:NSEnumerationConcurrent passingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
    BOOL match=NO;

    if( obj.finalGrade<100 ){
       match=YES;
    }
    return match;
}];

NSArray *courses=[coursesinfo objectsAtIndexes: theSet];
NSIndexSet*theSet=[coursesinfo IndexeSofObjects选项:NSEnumerationConcurrent passingTest:^BOOL(id obj,nsu整数idx,BOOL*stop){
布尔匹配=否;

如果(obj.finalgrade只需使用for-each循环并检查条件?这里有什么问题?我问是否有其他解决方案,如C中的where语句#阅读规范。有几种版本的
indexOfObjectPassingTest
,以及几种不同的排序选项。为什么会有很多否决票?这是个好问题,objective-C看起来不错在使用c#LINQ和lambda表达式之后,这就相当差劲了。只需使用for each循环并检查条件?这里有什么问题?我问是否有其他解决方案,如c#Read the spec中的where语句。有几个版本的
indexOfObjectPassingTest
,以及几个不同的排序选项。为什么会有很多否决票至少,这是一个好问题,objective-c在使用c#LINQ和lambda表达式后看起来相当蹩脚。