Showing posts with label compare. Show all posts
Showing posts with label compare. Show all posts

Wednesday, June 19, 2013

NSIndexPath compare example in Objective C (iOS).


NSIndexPath compare

Indicates the depth-first traversal order of the receiving index path and another index path.

- (NSComparisonResult)compare:(NSIndexPath *)indexPath

Parameters of [NSIndexPath compare]
indexPath
Index path to compare.
This value must not be nil. If the value is nil, the behavior is undefined.

Return Value of [NSIndexPath compare]
The depth-first traversal ordering of the receiving index path and indexPath.

NSOrderedAscending: The receiving index path comes before indexPath.
NSOrderedDescending: The receiving index path comes after indexPath.
NSOrderedSame: The receiving index path and indexPath are the same index path.
NSIndexPath compare example.
Try [indexPath1 compare: indexPath2] == NSOrderedSame.

Maybe you found a bug in NSIndexPath. If you try to create a new NSIndexPath with a path that already exists you should get that one instead. So isEqual: probably just compares the pointers and not the actual indices stored.

Example of [NSIndexPath compare].
NSComparisonResult result = [indexPath compare:[tempMutArray objectAtIndex:n];

if(result == NSOrderedSame) {
    // do stuff
}
In the Cocoa APIs, there are some non-class-types in use. Most important are those from the Foundation data types, which include

End of NSIndexPath compare example article.

Sunday, May 12, 2013

NSString compare example ios


compare:

Returns the result of invoking compare:options:range: with no options and the receiver’s full extent as the range.
- (NSComparisonResult)compare:(NSString *)aString
Parameters
aString
The string with which to compare the receiver.
This value must not be nil. If this value is nil, the behavior is undefined and may change in future versions of OS X.
Return Value of [NSString compare]
The result of invoking compare:options:range: with no options and the receiver’s full extent as the range.
Discussion of [NSString compare]
If you are comparing strings to present to the end-user, you should typically use localizedCompare: orlocalizedCaseInsensitiveCompare: instead.
Example of [NSString compare]
if([txtAnswer.text compare:answer options:NSCaseInsensitiveSearch] == NSOrderedSame)
{
    // Do somehing
}
Example of [NSString compare]
NSComparisonResult result = [selectedString compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];

NSString compare example ios


compare:

Returns the result of invoking compare:options:range: with no options and the receiver’s full extent as the range.
- (NSComparisonResult)compare:(NSString *)aString
Parameters
aString
The string with which to compare the receiver.
This value must not be nil. If this value is nil, the behavior is undefined and may change in future versions of OS X.
Return Value of [NSString compare]
The result of invoking compare:options:range: with no options and the receiver’s full extent as the range.
Discussion of [NSString compare]
If you are comparing strings to present to the end-user, you should typically use localizedCompare: orlocalizedCaseInsensitiveCompare: instead.
Example of [NSString compare]
if([txtAnswer.text compare:answer options:NSCaseInsensitiveSearch] == NSOrderedSame)
{
    // Do somehing
}
Example of [NSString compare]
NSComparisonResult result = [selectedString compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];

Thursday, May 9, 2013

NSDictionary compare example ios


isEqualToDictionary:  (NSDictionary compare)

Returns a Boolean value that indicates whether the contents of the receiving dictionary are equal to the contents of another given dictionary.
- (BOOL)isEqualToDictionary:(NSDictionary *)otherDictionary
Parameters (NSDictionary compare)
otherDictionary
The dictionary with which to compare the receiving dictionary.
Return Value  (NSDictionary compare)
YES if the contents of otherDictionary are equal to the contents of the receiving dictionary, otherwise NO.
Discussion  (NSDictionary compare)
Two dictionaries have equal contents if they each hold the same number of entries and, for a given key, the corresponding value objects in each dictionary satisfy the isEqual: test.
Example of (NSDictionary compare)
NSMutableDictionary *dictois = [[NSMutableDictionary new]autorelease];

[dictois setObject:@"easySpritedd" forKey:@"Nombre"];
[dictois setObject:@"X" forKey:@"290"];
[dictois setObject:@"Y" forKey:@"300"];

int fooIndex = [self.bloquesArray indexOfObjectPassingTest: ^(id obj, NSUInteger idx, BOOL *stop){
  if( [[obj class] isKindOfClass: [NSDictionary class]] ) {
    BOOL result = [obj isEqualToDictionary: diction];
    *stop = result;
    return result;
  }

  *stop = NO;
  return NO;

}];
Example of (NSDictionary compare)
- (BOOL) dictionaryArray:(NSMutableArray*)array containsDictionary:(NSDictionary*)givenDictionary
{
    BOOL result = NO;

    for( NSDictionary* dict in array )
    {
        if( [dict isEqualToDictionary:givenDictionary] )
        {
            result = YES;
        }
    }

    return result;
}