Pages

August 14, 2013

Search custom Object property in a NSArray (BOOL version)

How to find a custom-object-property value in a NSArray?
Well, use this convenient Objective-C function!
You need:
- http://objective-c-functions.blogspot.com/2013/08/search-custom-object-property-in.html


/** Search a bool in an array of objects.

 @param what Boolean value to look for.
 @param arr Array to search in.
 @param property String representing property to use in comparision
 @return Returns the index of first item found or -1 if not found.
 @see searchForString:inArray:usingProperty:
 @see searchForInteger:inArray:usingProperty:
 @see searchForFloat:inArray:usingProperty:

 */
+ (NSInteger)searchForBool:(BOOL)what inArray:(NSArray*)arr usingProperty:(NSString *)property {
    // Use the searchForInteger version with 1 or 0 according to "what" param.
    return [LMFunctions searchForInteger:(what ? 1 : 0) inArray:arr usingProperty:property];
}


Download the ready-for-use source file (.m) of Search custom Object property in a NSArray (BOOL version)

No comments:

Post a Comment