Class: NSPredicate

Inherits:
NSObject show all

Overview

The NSPredicate class is used to define logical conditions used to constrain a search either for a fetch or for in-memory filtering.

Direct Known Subclasses

NSComparisonPredicate, NSCompoundPredicate

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Class Method Details

+ (NSPredicate) predicateWithBlock(block)

Creates and returns a predicate that evaluates using a specified block object and bindings dictionary.

Parameters:

  • block

    The block is applied to the object to be evaluated.The block takes two arguments:evaluatedObjectThe object to be evaluated.bindingsThe substitution variables dictionary. The dictionary must contain key-value pairs for all variables in the receiver.The block returns YES if the evaluatedObject evaluates to true, otherwise NO.

  • evaluatedObject

    The object to be evaluated.

  • bindings

    The substitution variables dictionary. The dictionary must contain key-value pairs for all variables in the receiver.

Returns:

  • (NSPredicate)

    A new predicate by that evaluates objects using block.

+ (NSPredicate) predicateWithFormat(format, ...)

Creates and returns a new predicate formed by creating a new string with a given format and parsing the result. For details of the format of the format string and of limitations on variable substitution, see Predicate Format String Syntax.

Parameters:

  • format

    The format string for the new predicate.

  • ...

    A comma-separated list of arguments to substitute into format.

Returns:

  • (NSPredicate)

    A new predicate formed by creating a new string with format and parsing the result.

+ (NSPredicate) predicateWithFormat(predicateFormat, argumentArray:arguments)

Creates and returns a new predicate by substituting the values in a given array into a format string and parsing the result. For details of the format of the format string and of limitations on variable substitution, see Predicate Format String Syntax.

Parameters:

  • predicateFormat (String)

    The format string for the new predicate.

  • arguments (Array)

    The arguments to substitute into predicateFormat. Values are substituted into predicateFormat in the order they appear in the array.

Returns:

  • (NSPredicate)

    A new predicate by substituting the values in arguments into predicateFormat, and parsing the result.

+ (NSPredicate) predicateWithFormat(format, arguments:argList)

Creates and returns a new predicate by substituting the values in an argument list into a format string and parsing the result. For details of the format of the format string and of limitations on variable substitution, see Predicate Format String Syntax.

Parameters:

  • format (String)

    The format string for the new predicate.

  • argList (va_list)

    The arguments to substitute into predicateFormat. Values are substituted into predicateFormat in the order they appear in the argument list.

Returns:

  • (NSPredicate)

    A new predicate by substituting the values in argList into predicateFormat and parsing the result.

+ (NSPredicate) predicateWithValue(value)

Creates and returns a predicate that always evaluates to a given value.

Parameters:

  • value (Boolean)

    The value to which the new predicate should evaluate.

Returns:

  • (NSPredicate)

    A predicate that always evaluates to value.

Instance Method Details

- (Boolean) evaluateWithObject(object)

Returns a Boolean value that indicates whether a given object matches the conditions specified by the receiver.

Parameters:

  • object (Object)

    The object against which to evaluate the receiver.

Returns:

  • (Boolean)

    YES if object matches the conditions specified by the receiver, otherwise NO.

- (Boolean) evaluateWithObject(object, substitutionVariables:variables)

Returns a Boolean value that indicates whether a given object matches the conditions specified by the receiver after substituting in the values in a given variables dictionary. This method returns the same result as the two step process of first invoking predicateWithSubstitutionVariables: on the receiver and then invoking evaluateWithObject: on the returned predicate. This method is optimized for situations which require repeatedly evaluating a predicate with substitution variables with different variable substitutions.

Parameters:

  • object (Object)

    The object against which to evaluate the receiver.

  • variables (Hash)

    The substitution variables dictionary. The dictionary must contain key-value pairs for all variables in the receiver.

Returns:

  • (Boolean)

    YES if object matches the conditions specified by the receiver after substituting in the values in variables for any replacement tokens, otherwise NO.

- (String) predicateFormat

Returns the receiver’s format string.

Returns:

  • (String)

    The receiver’€™s format string.

- (NSPredicate) predicateWithSubstitutionVariables(variables)

Returns a copy of the receiver with the receiver’s variables substituted by values specified in a given substitution variables dictionary. The receiver itself is not modified by this method, so you can reuse it for any number of substitutions.

Parameters:

  • variables (Hash)

    The substitution variables dictionary. The dictionary must contain key-value pairs for all variables in the receiver.

Returns:

  • (NSPredicate)

    A copy of the receiver with the receiver’s variables substituted by values specified in variables.