Hi All, I have an array of objects, and use -filteredArrayUsingPredicate: to filter it.
The predicate is straight forward: description CONTAINS[cd] 'bravo' This works fine, unless the array contains a NSNotApplicableMarker object, which just gives me the rather useless error message: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't use in/contains operator with collection <NOT APPLICABLE MARKER> (not a collection)' I have attached sample code and the generated output below (note that [NSNotApplicableMarker description] returns a string). Are there any workarounds? Gerd Code: id o=[NSNotApplicableMarker description]; NSLog(@"NSNotApplicableMarker description: %@",o); NSLog(@"NSNotApplicableMarker description class: %@", NSStringFromClass([o class]) ); NSLog(@"NSNotApplicableMarker class: %@", NSStringFromClass([NSNotApplicableMarker class]) ); NSLog(@"NSNotApplicableMarker superclass: %@", NSStringFromClass([NSNotApplicableMarker superclass]) ); NSPredicate *testPredicate=[NSPredicate predicateWithFormat:@"description CONTAINS[cd] 'bravo'" ]; NSArray *array1=[NSArray arrayWithObjects: @"alpha", @"bravo", nil ]; NSLog(@"Test with array1 will work fine: %@", [array1 filteredArrayUsingPredicate:testPredicate] ); NSArray *array2=[NSArray arrayWithObjects: @"alpha", @"bravo", NSNotApplicableMarker, nil ]; NSLog(@"Test with array2 will throw exception: %@", [array2 filteredArrayUsingPredicate:testPredicate] ); Output: NSNotApplicableMarker description: <NOT APPLICABLE MARKER> NSNotApplicableMarker description class: NSCFString NSNotApplicableMarker class: _NSStateMarker NSNotApplicableMarker superclass: NSObject Test with array1 will work fine: ( bravo ) *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't use in/contains operator with collection <NOT APPLICABLE MARKER> (not a collection)' *** Call stack at first throw: ( 0 CoreFoundation 0x00007fff87b1f7b4 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x00007fff83d27f03 objc_exception_throw + 45 2 Foundation 0x00007fff86833037 -[NSInPredicateOperator performPrimitiveOperationUsingObject:andObject:] + 301 3 Foundation 0x00007fff86796825 -[NSComparisonPredicate evaluateWithObject:substitutionVariables:] + 301 4 Foundation 0x00007fff8679666a _filterObjectsUsingPredicate + 304 5 Foundation 0x00007fff867964c0 -[NSArray(NSPredicateSupport) filteredArrayUsingPredicate:] + 308 6 NSNotApplicableMarker_Predicate_Test 0x0000000100000d04 main + 532 7 NSNotApplicableMarker_Predicate_Test 0x0000000100000ae4 start + 52 8 ??? 0x0000000000000001 0x0 + 1 ) terminate called after throwing an instance of 'NSException' _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com