开发者

Core Data setReturnDistictResults Does it work on NSString *?

[request setReturnsDistinctResults:YES]; 

does not return distinct results for NSString *attribute?

for below example structure I have 17 managedObjects of kind Values with attribute assetGroupName and I am trying to fetch all distinct assetGroupNames value like

[request setResultType:NSDictionaryResultType]; 
[request setReturnsDistinctResults:YES];
[request setPropertiesToFetch :[NSArray arrayWithObject:@"assetGroupName"]];

but results still has argentina many times, and other countries too.


values =     (
                {
            assetCellValueLst =             {
                AskColorCode = "#B8D1ED";
                AskPrice = "102.20";
                BidColorCode = "#B8D1ED";
                BidPrice = "102.00";
                Name = "AR Bonar 11";
                PECSAsk = 569;
                PECSChg = "(31)";
                PECSChgColorCode = "#000000";
                PriceChg = "0.00";
                PriceChgColorCode = "#000000";
                SOLAsk = 604;
                SSPAsk = 677;
                SSPChgDay = "+3";
                SSPChgDayColorCode = "#000000";
                YTMAsk = "6.97";
                assetGroupName = Argentina;
                assetId = ARBONAR11;
                iconPath = "images/flag_Argentina.gif";
                updated = false;
            };
            assetId = ARBONAR11;
        },
                {
            assetCellValueLst =             {
                AskColorCode = "#53840f";
                AskPrice = "84.00";
                BidColorCode = "#53840f";
                BidPrice = "83.75";
                Name = "AR Bod 15";
                PECSAsk = 945;
                PECSChg = 14;
                PECSChgColorCode = "#000000";
                PriceChg = "-0.10";
                PriceChgColorCode = "#53840F";
                SOLAsk = 985;
                SSPAsk = 1007;
                SSPChgDay = "+7";
                SSPChgDayColorCode = "#000000";
                YTMAsk = "11.74";
                assetGroupName = Argentina;
                assetId = ARBON15;
                iconPath = "images/flag_Argentina.gif";
                updated = false;
            };
            assetId = ARBON15;
        },
                {
            assetCellValueLst =             {
                AskColorCode = "#53840f";
                AskPrice = "35.15";
                BidColorCode = "#53840f";
                BidPrice = "35.05";
                Name = "AR Bod 12";
                PECSAsk = "";
                PECSChg = "-";
                PECSChgColorCode = "#000000";
                PriceChg = "-0.10";
                PriceChgColorCode = "#53840F";
                SOLAsk = 675;
                SSPAsk = 721;
                SSPChgDay = "+22";
                SSPChgDayColorCode = "#000000";
                YTMAsk = "7.69";
                assetGroupName = Argentina;
                assetId = ARBON12;
                iconPath = "images/flag_Argentina.gif";
                updated = false;
            };
            assetId = ARBON12;
        },
                {
            assetCellValueLst =             {
                AskColorCode = "#B8D1ED";
                AskPrice = "97.00";
                BidColorCode = "#B8D1ED";
                BidPrice = "95.00";
                Name = "AR Bco Macro 17";
                PECSAsk = 669;
                PECSChg = "-";
                PECSChgColorCode = "#000000";
                PriceChg = "0.00";
                PriceChgColorCode = "#000000";
                SOLAsk = 690;
                SSPAsk = 709;
                SSPChgDay = "+3";
                SSPChgDayColorCode = "#000000";
                YTMAsk = "9.12";
                assetGroupName = Argentina;
                assetId = ARBCO17;
                iconPath = "images/flag_Argentina.gif";
                updated = false;
            };
            assetId = ARBCO17;
        },
                {
            assetCellValueLst =             {
                AskColorCode = "#B8D1ED";
                AskPrice = "120.00";
                BidColorCode = "#B8D1ED";
                BidPrice = "118.50";
                Name = "BR Braskem 15";
                PECSAsk = 268;
                PECSChg = 10;
                PECSChgColorCode = "#000000";
                PriceChg = "0.00";
                PriceChgColorCode = "#000000";
                SOLAsk = 294;
                SSPAsk = 316;
                SSPChgDay = "+3";
                SSPChgDayColorCode = "#000000";
                YTMAsk = "4.72";
                assetGroupName = Brazil;
                assetId = BRBRSKM15;
                iconPath = "images/flag_Brazil.gif";
                updated = false;
            };
            assetId = BRBRSKM15;
        },
                {
            assetCellValueLst =             {
                AskColorCode = "";
                AskPrice = "";
                BidColorCode = "";
                BidPrice = "";
                Name = "";
                PECSAsk = "";
                PECSChg = "";
                PECSChgColorCode = "#000000";
                PriceChg = "";
                PriceChgColorCode = "#000000";
                SOLAsk = "";
                SSPAsk = "";
                SSPChgDay = "";
                SSPChgDayColorCode = "#000000";
                YTMAsk = "";
                assetGroupName = Brazil;
                assetId = BRBND19;
                iconPath = "images/flag_Brazil.gif";
                updated = false;
            };
            assetId = BRBND19;
        },
                {
            assetCellValueLst =             {
                AskColorCode = "";
                AskPrice = "";
                BidColorCode = "";
                BidPrice = "";
                Name = "";
                PECSAsk = "";
                PECSChg = "";
                PECSChgColorCode = "#000000";
                PriceChg = "";
                PriceChgColorCode = "#000000";
                SOLAsk = "";
                SSPAsk = "";
                SSPChgDay = "";
                SSPChgDayColorCode = "#000000";
                YTMAsk = "";
                assetGroupName = Brazil;
                assetId = BRBND18;
                iconPath = "images/flag_Brazil.gif";
                updated = false;
            };
            assetId = BRBND18;
        },
                {
            assetCellValueLst =             {
                AskColorCode = "#B8D1ED";
                AskPrice = "109.11";
                BidColorCode = "#B8D1ED";
                BidPrice = "108.47";
                Name = "CL Rep 13";
                PECSAsk = 72;
                PECSChg = 12;
                PECSChgColorCode = "#000000";
                PriceChg = "0.00";
                PriceChgColorCode = "#000000";
                SOLAsk = 75;
                SSPAsk = 97;
                SSPChgDay = 0;
                SSPChgDayColorCode = "#000000";
                YTMAsk = "1.74";
                assetGroupName = Chile;
                assetId = CLREP13;
                iconPath = "images/flag_Chile.gif";
                updated = false;
            };
            assetId = CLREP13;
        },
                {
            assetCellValueLst =             {
                AskColorCode = "#B8D1ED";
                AskPrice = "125.00";
                BidColorCode = "#B8D1ED";
                BidPrice = "123.78";
                Name = "CL Codelco 19";
                PECSAsk = 130;
                PECSChg = 3;
                PECSChgColorCode = "#000000";
                PriceChg = "0.00";
                PriceChgColorCode = "#000000";
                SOLAsk = 138;
                SSPAsk = 145;
                SSPChgDay = "+3";
                SSPChgDayColorCode = "#000000";
                YTMAsk = "4.0";
                assetGroupName = Chile;
                assetId = CLCOD19;
                iconPath = "images/flag_Chile.gif";
                updated = false;
            };
            assetId = CLCOD19;
        },
                {
            assetCellValueLst =             {
                AskColorCode = "#53840f";
                AskPrice = "112.20";
                BidColorCode = "#53840f";
                BidPrice = "111.90";
                Name = "CO Rep 12";
                PECSAsk = 78;
                PECSChg = "(28)";
                PECSChgColorCode = "#000000";
                PriceChg = "0.20";
                PriceChgColorCode = "#53840F";
                SOLAsk = 82;
                SSPAsk = 134;
                SSPChgDay = "-14";
                SSPChgDayColorCode = "#000000";
                YTMAsk = "1.75";
                assetGroupName = Colombia;
                assetId = COREP12;
                iconPath = "images/flag_Colombia.gif";
                updated = false;
            };
            assetId = COREP12;
        },
                {
            assetCellValueLst =             {
                AskColorCode = "";
                AskPrice = "";
                BidColorCode = "";
                BidPrice = "";
                Name = "";
                PECSAsk = "";
                PECSChg = "";
                PECSChgColo开发者_如何学JAVArCode = "#000000";
                PriceChg = "";
                PriceChgColorCode = "#000000";
                SOLAsk = "";
                SSPAsk = "";
                SSPChgDay = "";
                SSPChgDayColorCode = "#000000";
                YTMAsk = "";
                assetGroupName = Colombia;
                assetId = COREP11;
                iconPath = "images/flag_Colombia.gif";
                updated = false;
            };
            assetId = COREP11;
        },
                {
            assetCellValueLst =             {
                AskColorCode = "#B8D1ED";
                AskPrice = "100.00";
                BidColorCode = "#B8D1ED";
                BidPrice = "100.00";
                Name = "CO Rep 10";
                PECSAsk = "";
                PECSChg = "-";
                PECSChgColorCode = "#000000";
                PriceChg = "0.00";
                PriceChgColorCode = "#000000";
                SOLAsk = "";
                SSPAsk = "";
                SSPChgDay = "";
                SSPChgDayColorCode = "#000000";
                YTMAsk = "";
                assetGroupName = Colombia;
                assetId = COREP10;
                iconPath = "images/flag_Colombia.gif";
                updated = false;
            };
            assetId = COREP10;
        },
                {
            assetCellValueLst =             {
                AskColorCode = "#53840f";
                AskPrice = "112.00";
                BidColorCode = "#53840f";
                BidPrice = "111.25";
                Name = "CO EEB 14";
                PECSAsk = 367;
                PECSChg = 5;
                PECSChgColorCode = "#000000";
                PriceChg = "0.25";
                PriceChgColorCode = "#53840F";
                SOLAsk = 395;
                SSPAsk = 417;
                SSPChgDay = "-4";
                SSPChgDayColorCode = "#000000";
                YTMAsk = "5.55";
                assetGroupName = Colombia;
                assetId = COEEB14;
                iconPath = "images/flag_Colombia.gif";
                updated = false;
            };
            assetId = COEEB14;
        },
                {
            assetCellValueLst =             {
                AskColorCode = "#B8D1ED";
                AskPrice = "109.25";
                BidColorCode = "#B8D1ED";
                BidPrice = "108.00";
                Name = "ID PLNJ 37";
                PECSAsk = 353;
                PECSChg = 8;
                PECSChgColorCode = "#000000";
                PriceChg = "0.00";
                PriceChgColorCode = "#000000";
                SOLAsk = 367;
                SSPAsk = 353;
                SSPChgDay = "+2";
                SSPChgDayColorCode = "#000000";
                YTMAsk = "7.1";
                assetGroupName = Indonesia;
                assetId = IDPLNJ37;
                iconPath = "images/flag_Indonesia.gif";
                updated = false;
            };
            assetId = IDPLNJ37;
        },


This:

[request setPropertiesToFetch :[NSArray arrayWithObject:@"assetGroupName"]];

... is wrong. You need to pass an array of NSPropertyDescription objects not just a string with the properties name.

So:

NSEntityDescription *theEntity=[NSEntityDescription entityForName:@"Values" inManagedObjectContext:self.moc];
NSDictionary *entityProps=[theEntity propertiesByName];
NSPropertyDescription *assetGroupNameDescript=[entityProps valueForKey:@"assetGroupName"]];
//...
[request setPropertiesToFetch :[NSArray arrayWithObject:assetGroupNameDescript];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜