macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

compareObject:toObject:

2つのオブジェクトを比較した結果を返します
-(NSComparisonResult)compareObject:(id)object1:
     toObject:(id)object2:

解説

2つのオブジェクトを比較した結果を返します。

返り値

( NSComparisonResult )

比較結果

引数

( id )object1
( id )object2

クラス

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