compareObject:toObject:
2つのオブジェクトを比較した結果を返します
-(NSComparisonResult)compareObject:(id)object1: toObject:(id)object2:
解説
2つのオブジェクトを比較した結果を返します。
返り値
( NSComparisonResult )
比較結果
引数
( id )object1
( id )object2
フレームワーク
Foundation
クラス
NSSortDescriptor
Instance Methods
使用可能
10.3
参照
例文
#import "MyObject.h" #import "MySortDescripter.h" @implementation MyObject //myOutlet テーブルビュー //tColumn1 テーブルコラム //tColumn2 テーブルコラム - (IBAction)myAction:(id)sender { MySortDescripter *descriptor=[[[NSSortDescriptor alloc] initWithKey:@"key1" ascending:NO] autorelease]; [tColumn1 setSortDescriptorPrototype:descriptor]; NSLog(@"%@",[[tColumn1 sortDescriptorPrototype] description]); switch ([descriptor compareObject:[NSNumber numberWithInt:1] toObject:[NSNumber numberWithInt:2]]){ case NSOrderedAscending: NSLog(@"NSOrderedAscending"); break; case NSOrderedSame: NSLog(@"NSOrderedSame"); break; case NSOrderedDescending: NSLog(@"NSOrderedDescending"); break; } } @end