0

「メジャー」と対多の関係にあるアカウントオブジェクトがたくさんあります... account.measures<--->measure.measureaccount

特定のアカウントについて、コアデータモデルで文字列として指定された個別のメジャータイプを返そうとしています:

ここに画像の説明を入力

しかし、個々のメジャー タイプをすべて取得します。

- (NSArray *)getDistinctMeasuresForAccount: (BM_Account *)account
{

    NSManagedObjectContext *myContext=[self managedObjectContext];
    NSEntityDescription *entity=[NSEntityDescription entityForName:@"BM_Measure" inManagedObjectContext:myContext];
    [findObjects setEntity:entity];

    NSDictionary *entityProperties = [entity propertiesByName];
    [findObjects setPropertiesToFetch:[NSArray arrayWithObject:[entityProperties objectForKey:@"measuretype"]]];

    [findObjects setReturnsDistinctResults:TRUE];
    findObjects.fetchBatchSize=1;
    findObjects.fetchLimit=0;
    NSPredicate *myObjectPredicate = [NSPredicate predicateWithFormat:@"measureAccount = %@",account];
    findObjects.predicate=myObjectPredicate;
    findObjects.resultType = NSDictionaryResultType;
    NSSortDescriptor *sortReturnedObjects=[NSSortDescriptor sortDescriptorWithKey:@"measuretype" ascending:FALSE];
    findObjects.sortDescriptors = [NSArray arrayWithObjects:sortReturnedObjects, nil];
    NSError *findError;
    NSArray *databaseObjects=[myContext executeFetchRequest:findObjects error:&findError];
    if(databaseObjects==nil){
        NSLog(@"BM.DB.getDistinctMeasuresForAccount: Unable to execute query to get Objects");
        return nil;
    }
    else
    {
        NSLog(@"About to return %ld %@",[databaseObjects count],databaseObjects);
        return(databaseObjects);
    }
    NSLog(@"BM.DB.getDistinctMeasuresForAccount: Returning zero because of open query");
    return 0;


}

出力:

About to return 347 (
        {
        measuretype = Weight;
    },
        {
        measuretype = Weight;
    },
        {
        measuretype = Weight;
    },
        {
        measuretype = Weight;
    },
        {
        measuretype = Weight;
    },
        {
        measuretype = Weight;
    },
        {
        measuretype = Weight;
    },
        {
        measuretype = Weight;
    },
        {
        measuretype = Weight;
    },
        {
        measuretype = Weight;
    },
        {
        measuretype = Weight;
    },
        {
        measuretype = Weight;
    },
        {
        measuretype = Weight;
    },
        {
        measuretype = Weight;
    },
        {
        measuretype = Weight;
    },
...
4

1 に答える 1

0

Xcode の最新バージョンのデフォルト コンストラクターは xml データベースを作成することが判明したため、distinct はサポートされていません。

于 2013-11-03T13:00:55.327 に答える