从数据数组中提取唯一对象 [英] Extracting Unique Objects from a Data Array
本文介绍了从数据数组中提取唯一对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想仅在数据数组中以前不存在名称时才在数据数组中添加名称。当我试图打印这些名字时,我会重复这些。有没有办法解决这个问题?
I want to add names in a data array only if the name does not previously exist in the data array. When I attempt to print these names, I do get repetitions. Is there a way to solve this?
-(NSMutableArray *)autoComplete
{
NSMutableArray *dataArray = [[NSMutableArray alloc] init];
NSString *url = [NSString stringWithFormat:@"%@45.25,-95.25&limit=100&client_id=Von0J4Bu6INiez5bGby2R&client_secret=50sUjSbg7dba8cQgtpdfr5Ns7wyYTqtmKpUU3khQ",kWSURL];
NSDictionary * returnDict = (NSDictionary *) [self callWebService:url];
if([returnDict objectForKey:@"success"])
{
NSArray *responceArray = [returnDict objectForKey:@"response"];
for (NSDictionary *dict in responceArray) {
placeDC *place = [[placeDC alloc]init];
NSDictionary *placeDict = (NSDictionary *)[dict objectForKey:@"place" ];
NSDictionary *loctionDict =(NSDictionary *)[dict objectForKey:@"loc"];
NSString * name =[placeDict objectForKey:@"name"];
NSString * stateFull =[placeDict objectForKey:@"stateFull"];
NSString * countryFull =[placeDict objectForKey:@"countryFull"];
NSString *latitude =[loctionDict objectForKey:@"lat"];
NSString *longitude = [loctionDict objectForKey:@"long"];
place.placeNmae=name;
place.countryFullName=countryFull;
place.stateFullName=stateFull;
NSLog(@"%@ ",stateFull);
place.latitude=[latitude doubleValue];
place.longitude=[longitude doubleValue];
[dataArray addObject:place];
}
}
return dataArray;
}
推荐答案
首先检查那里有没有来自服务器端的响应,检查响应是否使用NSLog()或断点。
First Check that is there any response from the Server side or not, to check response use NSLog() or Break Points.
如果响应正常,则进行以下检查您的代码
if response is ok then put a the following check your code
if (![dataArray containsObject:@"Some Name"])
{
// add Object
}
这篇关于从数据数组中提取唯一对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文