how to sort an array by integer - iphone

i am trying to sort my score board but the score board is sorted by name but i want sort it by score i.e (high to low) score plese help to solve this.i stored the playername and score details in one label.
please help me
thanks in advance
asd 45
asd 66
rrr 55
tes 42
i want to show like
asd 66
rrr 55
asd 45
tes 42
-(void)btnSaveScore
{
if(!dictWinData)
dictWinData = [[NSMutableDictionary alloc] init];
array = [[NSMutableArray alloc] init];
array = [[[NSUserDefaults standardUserDefaults] valueForKey:#"ScoreName"] mutableCopy];
if([array count] == 0)
{
array = [[NSMutableArray alloc] init];
}
NSString *strName = [NSString stringWithFormat:#"%#",strNameOFPlayer];
NSString *strScore = [NSString stringWithFormat:#"%#",[NSString stringWithFormat:#"%d",iTap]];
int intScore = iTap;
NSLog(#"iTap data is:--> %d",intScore);
if([strNameOFPlayer length]==7)
[array addObject:[NSString stringWithFormat:#"%# %#",strName,strScore]];
else if ([strNameOFPlayer length] == 6)
[array addObject:[NSString stringWithFormat:#"%# %#",strName,strScore]];
else if ([strNameOFPlayer length] == 5)
[array addObject:[NSString stringWithFormat:#"%# %#",strName,strScore]];
else if ([strNameOFPlayer length] == 4)
[array addObject:[NSString stringWithFormat:#"%# %#",strName,strScore]];
else if ([strNameOFPlayer length] == 3)
[array addObject:[NSString stringWithFormat:#"%# %#",strName,strScore]];
else if ([strNameOFPlayer length] == 2)
[array addObject:[NSString stringWithFormat:#"%# %#",strName,strScore]];
else if ([strNameOFPlayer length] == 1)
[array addObject:[NSString stringWithFormat:#"%# %#",strName,strScore]];
NSSortDescriptor *sorter = [[NSSortDescriptor alloc] initWithKey:#"self" ascending:YES];
NSArray *sorters = [[NSArray alloc] initWithObjects:sorter, nil];
[sorter release];
NSArray *sortedArray = [array sortedArrayUsingDescriptors:sorters];
[sorters release];
NSUserDefaults *dfltsData = [NSUserDefaults standardUserDefaults];
[dfltsData setObject:sortedArray forKey:#"ScoreName"];
// [dfltsData setObject:array forKey:#"ScoreCard"];
[dfltsData synchronize];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert"
message:#"Score is saved."
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles:nil, nil];
[alert show];
[alert release];
}

Here you are adding the string (containing name and score) to the array. Instead, create a model class with the name (NSString*) and score (NSNumber*) members and add them to the array.
For sorting,
NSArray *sortedArray = [yourUnsortedArray sortedArrayUsingComparator: ^(id obj1, id obj2) {
if ([[obj1 score] integerValue] > [[obj2 score] integerValue]) {
return NSOrderedDescending;
}
if ([[obj1 score] integerValue] < [[obj2 score] integerValue]) {
return NSOrderedAscending;
}
return NSOrderedSame;
}];

Related

iPhone : How to get each element from QR code vCard?

I am developing one simple application which is used to read the QR code vCard and display the details of the contact information in the QR code vCard. I am able to scan the vCard and get the details about the contact as follows
BEGIN:VCARD
VERSION:2.1
N:XX;XXXXXXXX
FN:XXXXXXXXX XX
TEL;WORK;VOICE:91999999999
EMAIL;WORK;INTERNET:sac#gmail.com
END:VCARD
But I need to parse each element in it. How to parse the details and what are the ways to parse?
The documentation points to this method:
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results){
NSString *upcString = symbol.data;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Scanned UPC" message:[NSString stringWithFormat:#"The UPC read was: %#", upcString] delegate:self cancelButtonTitle:nil otherButtonTitles:#"Ok", nil];
[alert show];
[reader dismissModalViewControllerAnimated: YES];
}
}
i would first see what it returns maybe try looping the dictionary for additional data
Well its being quite a long time that this question is asked. But answering now might also help someone who is navigated to this page. You can use the below method for reference to parse the VCF data.
NSString *str = [NSString stringWithString:response.vcfString];
NSArray *subStrings = [str componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"\n"]];
NSArray *getData = [[NSArray alloc]init];
NSString *arr = #"";
for (int i=0;i<[subStrings count];i++)
{
arr = [subStrings objectAtIndex:i];
NSArray *abc = [arr componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#";"]];
if([[abc objectAtIndex:0] isEqualToString:#"FN"])
{
getData=[[abc objectAtIndex:1] componentsSeparatedByCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:#":"] ];
if([getData count] > 1)
fullName = [getData objectAtIndex:1];
}
else if([[abc objectAtIndex:0] isEqualToString:#"N"])
{
getData=[[abc objectAtIndex:1] componentsSeparatedByCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:#":"]];
if([getData count] > 1)
lastName = [getData objectAtIndex:1];
FirstName = [abc objectAtIndex:2];
}
else if([[abc objectAtIndex:0] isEqualToString:#"TITLE"])
{
getData=[[abc objectAtIndex:1] componentsSeparatedByCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:#":"]];
if([getData count] > 1)
title = [getData objectAtIndex:1];
}
else if([[abc objectAtIndex:0] isEqualToString:#"TEL"])
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
if([abc count] == 3)
{
getData=[[abc objectAtIndex:2] componentsSeparatedByCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:#":"]];
if([[abc objectAtIndex:1] isEqualToString:#"WORK"])
{
if([getData count] > 1)
[dict setObject:[getData objectAtIndex:1] forKey:#"Tel"];
}
else if([[abc objectAtIndex:1] isEqualToString:#"CELL"])
{
if([getData count] > 1)
[dict setObject:[getData objectAtIndex:1] forKey:#"Tel"];
}
}
else if([abc count] == 4)
{
getData=[[abc objectAtIndex:3] componentsSeparatedByCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:#":"]];
if([[abc objectAtIndex:1] isEqualToString:#"WORK"] && [[abc objectAtIndex:2] isEqualToString:#"FAX"])
{
if([getData count] > 1)
[dict setObject:[getData objectAtIndex:1] forKey:#"Tel"];
}
}
else
{
getData=[[abc objectAtIndex:1] componentsSeparatedByCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:#":"]];
if([[getData objectAtIndex:0] isEqualToString:#"WORK"])
{
if([getData count] > 1)
[dict setObject:[getData objectAtIndex:1] forKey:#"Tel"];
}
else if([[getData objectAtIndex:0] isEqualToString:#"FAX"])
{
if([getData count] > 1)
[dict setObject:[getData objectAtIndex:1] forKey:#"Tel"];
}
}
[_telList addObject:dict];
}
else if([[abc objectAtIndex:0] isEqualToString:#"EMAIL"])
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
if([abc count] == 3)
{
getData=[[abc objectAtIndex:2] componentsSeparatedByCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:#":"]];
if([[abc objectAtIndex:1] isEqualToString:#"WORK"])
{
if([getData count] > 1)
[dict setObject:[getData objectAtIndex:1] forKey:#"Email"];
}
}
else
{
getData=[[abc objectAtIndex:1] componentsSeparatedByCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:#":"]];
if([getData count] > 1)
[dict setObject:[getData objectAtIndex:1] forKey:#"Email"];
}
[_emailList addObject:dict];
}
else if([[abc objectAtIndex:0] isEqualToString:#"ORG"])
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
if([abc count] == 5)
{
getData=[[abc objectAtIndex:2] componentsSeparatedByCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:#":"]];
if([[abc objectAtIndex:1] isEqualToString:#"WORK"])
{
NSString *orgStr = #"";
if([getData count] > 1)
{
orgStr = [getData objectAtIndex:1];
}
[dict setObject:[orgStr stringByAppendingString:[abc objectAtIndex:4]] forKey:#"Org"];
}
}
else
{
getData=[[abc objectAtIndex:1] componentsSeparatedByCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:#":"]];
if([getData count] > 1)
[dict setObject:[getData objectAtIndex:1] forKey:#"Org"];
}
[_orgList addObject:dict];
}
else if([[abc objectAtIndex:0] isEqualToString:#"ADR"])
{
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
if([abc count] == 9)
{
[dict setObject:[abc objectAtIndex:4] forKey:#"Add"];
[dict setObject:[abc objectAtIndex:8] forKey:#"Country"];
[dict setObject:[abc objectAtIndex:7] forKey:#"Zip"];
[dict setObject:[abc objectAtIndex:5] forKey:#"City"];
}
else
{
}
[_addrList addObject:dict];
}
else if([[abc objectAtIndex:0] isEqualToString:#"URL"])
{
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
if([abc count] == 3)
{
getData=[[abc objectAtIndex:2] componentsSeparatedByCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:#":"]];
if([getData count] > 1)
[dict setObject:[getData objectAtIndex:1] forKey:#"Url"];
}
else
{
getData=[[abc objectAtIndex:1] componentsSeparatedByCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:#":"]];
if([getData count] > 1)
[dict setObject:[getData objectAtIndex:1] forKey:#"Url"];
}
[_urlList addObject:dict];
}
else
{
}
}
NSLog(#"Details: \nFull Name - %#\nLast Name - %#\nFirst Name - %#\ntitle - %#\nEmail - %#\norg - %#\nAddress - %#\nUrl - %#", fullName,lastName,FirstName,title,[[_emailList valueForKey:#"description"] componentsJoinedByString:#""],[_orgList description],[_addrList description],[_urlList description] );
you can use Encoder of QRCode
Encoder
You can use CNContactVCardSerialization to get CNContact Object from data
import Contacts
if let data = str.data(using: .utf8) {
do {
let contacts = try CNContactVCardSerialization.contacts(with: data)
let contact = contacts.first
print("\(String(describing: contact?.familyName))")
return contact
} catch {
print("Contact Error: \(error.localizedDescription)")
}
}

can i sort stored score in nsuserdefaults?

i am developing game application ,in that app i am storing name,score in nsuserdefaults ....but
the according to my requirement i want to store name and score (high to low) based on score ....is there any solution for sorting score in nsuserdefaults... i want show my high score on top
thank's in adv
-(void)btnSaveScore
{
if(!dictWinData)
dictWinData = [[NSMutableDictionary alloc] init];
array = [[NSMutableArray alloc] init];
array = [[[NSUserDefaults standardUserDefaults] valueForKey:#"ScoreName"] mutableCopy];
if([array count] == 0)
{
array = [[NSMutableArray alloc] init];
}
NSString *strName = [NSString stringWithFormat:#"%#",strNameOFPlayer];
NSString *strScore = [NSString stringWithFormat:#"%#",[NSString stringWithFormat:#"%d",iTap]];
if([strNameOFPlayer length]==7)
[array addObject:[NSString stringWithFormat:#"%# %#",strName,strScore]];
else if ([strNameOFPlayer length] == 6)
[array addObject:[NSString stringWithFormat:#"%# %#",strName,strScore]];
else if ([strNameOFPlayer length] == 5)
[array addObject:[NSString stringWithFormat:#"%# %#",strName,strScore]];
else if ([strNameOFPlayer length] == 4)
[array addObject:[NSString stringWithFormat:#"%# %#",strName,strScore]];
else if ([strNameOFPlayer length] == 3)
[array addObject:[NSString stringWithFormat:#"%# %#",strName,strScore]];
else if ([strNameOFPlayer length] == 2)
[array addObject:[NSString stringWithFormat:#"%# %#",strName,strScore]];
else if ([strNameOFPlayer length] == 1)
[array addObject:[NSString stringWithFormat:#"%# %#",strName,strScore]];
NSUserDefaults *dfltsData = [NSUserDefaults standardUserDefaults];
[dfltsData setObject:array forKey:#"ScoreName"];
[dfltsData synchronize];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert"
message:#"Score is saved."
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles:nil, nil];
[alert show];
[alert release];
please help me out
Get array from NSUserDefault like this:
NSMutableArray *arrScores = [[NSUserDefaults standardUserDefaults] ObjectforKey:#"ScoreName"];
Now sort arrScores should only contain strScore value only using below method:
-(NSMutableArray *)sortByfloatvalue:(NSMutableArray *)array
{
for(int i=0;i<[array count];i++)
{
for(int j=i+1;j<[array count];j++)
{
if([[array objectAtIndex:i] floatValue] < [[array objectAtIndex:j] floatValue])
{
[array exchangeObjectAtIndex:i withObjectAtIndex:j];
}
}
}
return array;
}

Memory leak in NSMutableArray, NSArray, NSString in iPhone SDK

In my app, I got Memory leaks in NSMutableArray, NSArray and NSString.
Here is the code.
NSString *subQuery = [NSString stringWithFormat:#"SELECT %# FROM tbl_lang WHERE glossary = '%#'",append1,glossaryName];
NSArray *subArray1 = [[[self returnExecuteQuery:subQuery] mutableCopy] autorelease];
[subArray addObjectsFromArray:subArray1];
NSString *columnQuery = [NSString stringWithFormat:#"select AutoID,%# from tbl_lang where glossary='%#'",lblshortName.text,glossaryName];
NSArray *newArray =[[[self returnExecuteQuery:columnQuery] mutableCopy] autorelease];
[langArray addObjectsFromArray:newArray];
NSMutableArray *tempArray = [[NSMutableArray alloc] init];
for (int i=0; i<[newArray count]; i++) {
NSString *cellText = [[newArray objectAtIndex:i] valueForKey:[NSString stringWithFormat:#"%#",lblshortName.text]];
if (cellText != (NSString *)[NSNull null] && ![cellText isEqualToString:#""] ) {
NSString *decodedString3 = [NSString stringWithUTF8String:[cellText cStringUsingEncoding:[NSString defaultCStringEncoding]]];
[tempArray addObject:[NSString stringWithFormat:#"%# : %#",lblshortName.text, decodedString3]];
}
else {
[tempArray addObject:#"<empty>"];
}
NSString *detail = #"_________________";
for (int j=0; j<[lableNameArray count]; j++) {
NSString *checkNull=[[subArray1 objectAtIndex:i] valueForKey:[NSString stringWithFormat:#"%#",[lableNameArray objectAtIndex:j]]];
if(checkNull != (NSString *)[NSNull null] && checkNull.length > 0)
{
NSString *decodedString4 = [NSString stringWithUTF8String:[checkNull cStringUsingEncoding:[NSString defaultCStringEncoding]]];
detail = [NSString stringWithFormat:#"%#\n%# : %# ",detail,[lableNameArray objectAtIndex:j],decodedString4];
}
}
[detailTextArray addObject:detail];
}
When I run in Instruments I got leaks in
-subArray1 in second line.
-detail (NSString) in second for loop.
And subArray and langArray are my global arrays.
If I remove mutableCopy from NSArray *newArray =[[[self returnExecuteQuery:columnQuery] mutableCopy] autorelease]; and NSArray *subArray1 = [[[self returnExecuteQuery:subQuery] mutableCopy] autorelease]; then subArray and langArray doesnot retain values.
How to avoid memory leak in this code?
Olease try this one, in above code you are creating two many objects that belong to autorelease pool here is one version where I tried to handle release of those string variables.
Second this is that the leak of detail is because you are de-referencing it many times in your code. And for subArray1 please see the comment
NSMutableString *subQuery =[ [NSMutableString alloc] initWithFormat:#"SELECT %# FROM tbl_lang WHERE glossary = '%#'",append1,glossaryName];
// please make returnExecuteQuery's returned array autorelease if it is not.
NSArray *subArray1 = [[self returnExecuteQuery:subQuery] mutableCopy] ;
[subArray addObjectsFromArray:subArray1];
[subQuery release];
NSMutableString *columnQuery ==[ [NSMutableString alloc] initWithFormat:#"select AutoID,%# from tbl_lang where glossary='%#'",lblshortName.text,glossaryName];
NSArray *newArray =[[self returnExecuteQuery:columnQuery] mutableCopy] ;
[langArray addObjectsFromArray:newArray];
[columnQuery relese];
NSMutableArray *tempArray = [[NSMutableArray alloc] init];
for (int i=0; i<[newArray count]; i++) {
NSMutableString *tempKey = [[NSMutableString alloc]initWithFormat:#"%#",lblshortName.text]];
NSString *cellText = [[newArray objectAtIndex:i] valueForKey:tempKey];
[tempKey release];
if (cellText != (NSString *)[NSNull null] && ![cellText isEqualToString:#""] ) {
NSString *decodedString3 = [NSString stringWithUTF8String:[cellText cStringUsingEncoding:[NSString defaultCStringEncoding]]];
NSMutableString *tempString = [[NSMutableString alloc] initWithFormat:#"%# : %#",lblshortName.text, decodedString3]];
[tempArray addObject:tempString];
[tempString release];
}
else {
[tempArray addObject:#"<empty>"];
}
NSMutableString *detail = nil;
for (int j=0; j<[lableNameArray count]; j++)
{
detail = [[ NSMutableString alloc]initWithString:#"_________________"];
NSMutableString *key = [[NSMutableString alloc]initWithFormat:#"%#",[lableNameArray objectAtIndex:j]];
NSString *checkNull=[[subArray1 objectAtIndex:i] valueForKey:key];
[key release];
if(checkNull != (NSString *)[NSNull null] && checkNull.length > 0)
{
NSString *decodedString4 = [NSString stringWithUTF8String:[checkNull cStringUsingEncoding:[NSString defaultCStringEncoding]]];
[detail setString:[NSString stringWithFormat:#"%#\n%# : %# ",detail,[lableNameArray objectAtIndex:j],decodedString4]];
}
[detailTextArray addObject:detail];
[detail release];
}
}
[subArray1 release];
[newArray release];
UPDATE : Please do read comments in the code and reply back so that things could be improved.
NSMutableString *subQuery =[ [NSMutableString alloc] initWithFormat:#"SELECT %# FROM tbl_lang WHERE glossary = '%#'",append1,glossaryName];
//*****NOTE THIS POINT ----> please make returnExecuteQuery's returned array autorelease if it is not.
NSArray *subArray1 = [[self returnExecuteQuery:subQuery] mutableCopy] ;
[subArray addObjectsFromArray:subArray1];
[subQuery release];
NSMutableString *columnQuery ==[ [NSMutableString alloc] initWithFormat:#"select AutoID,%# from tbl_lang where glossary='%#'",lblshortName.text,glossaryName];
//*****NOTE THIS POINT ----> please make returnExecuteQuery's returned array autorelease if it is not.
NSArray *newArray =[[self returnExecuteQuery:columnQuery] mutableCopy] ;
[langArray addObjectsFromArray:newArray];
[columnQuery relese];
NSMutableArray *tempArray = [[NSMutableArray alloc] init];
for (int i=0; i<[newArray count]; i++) {
NSMutableString *tempKey = [[NSMutableString alloc]initWithFormat:#"%#",lblshortName.text]];
NSString *cellText = [[newArray objectAtIndex:i] valueForKey:tempKey];
[tempKey release];
if (cellText != (NSString *)[NSNull null] && ![cellText isEqualToString:#""] ) {
NSString *decodedString3 = [NSString stringWithUTF8String:[cellText cStringUsingEncoding:[NSString defaultCStringEncoding]]];
NSMutableString *tempString = [[NSMutableString alloc] initWithFormat:#"%# : %#",lblshortName.text, decodedString3]];
[tempArray addObject:tempString];
[tempString release];
}
else {
[tempArray addObject:#"<empty>"];
}
NSMutableString *detail = [[ NSMutableString alloc]initWithString:#"_________________"];
for (int j=0; j<[lableNameArray count]; j++)
{
NSMutableString *key = [[NSMutableString alloc]initWithFormat:#"%#",[lableNameArray objectAtIndex:j]];
NSString *checkNull=[[subArray1 objectAtIndex:i] valueForKey:key]; //also here if you note you are using subArray1 not subArray?
[key release];
if(checkNull != (NSString *)[NSNull null] && checkNull.length > 0)
{
NSString *decodedString4 = [NSString stringWithUTF8String:[checkNull cStringUsingEncoding:[NSString defaultCStringEncoding]]];
[detail setString:[NSString stringWithFormat:#"%#\n%# : %# ",detail,[lableNameArray objectAtIndex:j],decodedString4]];
break;//I am not sure why you are checking this condition but assume that you want to get NOT NULL VALUE and add it to array?
}
}
[detailTextArray addObject:detail];
[detail release];
}
[subArray1 release];
[newArray release];
UPDATE 2:
if(checkNull != (NSString *)[NSNull null] && checkNull.length > 0)
{
NSString *decodedString4 = [NSString stringWithUTF8String:[checkNull cStringUsingEncoding:[NSString defaultCStringEncoding]]];
[detail appendFormat:#"%#\n%# : %# ",detail,[lableNameArray objectAtIndex:j],decodedString4]];
}
Thanks,
Not sure what is causing the memory leak, but this may help. This is a more direct way of copying the arrays, and may result in avoiding the leak:
NSArray *langArray =[[NSArray alloc] initWithArray: [self returnExecuteQuery:columnQuery] copyItems: YES];
This basically makes a one-level deep copy of the array returned by returnExecuteQuery. You can read about it in more detail in Collections Programming Topics.
I'm not sure how mutableCopy works and that may have something to do with the leak. If it copies the objects in the old array & then adds them to the new array, they may enter the array with a retain count of 2 (1 from the copy, and 1 from being added to an array.) It doesn't make much sense that it should work this way. But, if it does, that could account for the leak.
You could start by releasing your tempArray once done with it (after the loops).
Often, the higher levels leaks are hidden in the flood of lower level ones (ie a container leaking causes all its content to be leaked as well), which might be the case for your string.
Using mutableCopy] autorelease]; is fine by the way.

UISearchBar - search a NSDictionary of Arrays of Objects

I'm trying to insert a search bar in a tableview, that is loaded with information from a NSDictionary of Arrays. Each Array holds and object. Each object has several properties, such as Name or Address.
I've implemented the methods of NSSearchBar, but the code corresponding to the search it self, that i have working on another project where the Arrays have strings only, is not working, and I can't get to thr problem.
Here's the code:
'indiceLateral' is a Array with the alphabet;
'partners' is a NSDictionary;
'RLPartnersClass' is my class of Partners, each one with the properties (name, address, ...).
-(void)handleSearchForTerm:(NSString *)searchTerm {
NSMutableArray *sectionsToRemove = [[NSMutableArray alloc] init];
[self resetSearch];
for (NSString *key in self.indiceLateral) {
NSMutableArray *array = [partners valueForKey:key];
NSMutableArray *toRemove = [[NSMutableArray alloc] init];
for (NSString *name in array) {
if ([name rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location == NSNotFound)
[toRemove addObject:name];
}
if ([array count] == [toRemove count])
[sectionsToRemove addObject:key];
[array removeObjectsInArray:toRemove];
[toRemove release];
}
[self.indiceLateral removeObjectsInArray:sectionsToRemove];
[sectionsToRemove release];
[theTable reloadData];
}
Can anyone help me please?
Thanks,
Rui Lopes
I've done it.
Example:
-(void)handleSearchForTerm:(NSString *)searchTerm {
NSMutableDictionary *finalDict = [NSMutableDictionary new];
NSString *currentLetter = [[NSString alloc] init];
for (int i=0; i<[indiceLateral count]; i++) {
NSMutableArray *elementsToDict = [[[NSMutableArray alloc] init] autorelease];
currentLetter = [indiceLateral objectAtIndex:i];
NSArray *partnersForKey = [[NSArray alloc] initWithArray:[partnersCopy objectForKey:[indiceLateral objectAtIndex:i]]];
for (int j=0; j<[partnersForKey count]; j++) {
RLNames *partnerInKey = [partnersForKey objectAtIndex:j];
NSRange titleResultsRange = [partnerInKey.clientName rangeOfString:searchTerm options:NSDiacriticInsensitiveSearch | NSCaseInsensitiveSearch];
if (titleResultsRange.length > 0){
NSLog(#"found: %#", partnerInKey.clienteCity
[elementsToDict addObject:partnerInKey];
}
}
[finalDict setValue:elementsToDict forKey:currentLetter];
}
NSMutableDictionary *finalResultDict = [finalDict mutableDeepCopy];
self.partners = finalResultDict;
[finalResultDict release];
[theTable reloadData];
}

TouchXML to read in twitter feed for iphone app

So I've managed to get the feed from twitter and am attempting to parse it...
I only require the following fields from the feed:
name, description, time_zone and created_at
I am successfully pulling out name and description.. however time_zone and created_at always are nil... The following is the code...
Anyone see why this might not be working?
-(void) friends_timeline_callback:(NSData *)data{
NSString *string = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(#"Data from twitter: %#", string);
NSMutableArray *res = [[NSMutableArray alloc] init];
CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:data options:0 error:nil] autorelease];
NSArray *nodes = nil;
//! searching for item nodes
nodes = [doc nodesForXPath:#"/statuses/status/user" error:nil];
for (CXMLElement *node in nodes)
{
int counter;
Contact *contact = [[Contact alloc] init];
for (counter = 0; counter < [node childCount]; counter++)
{
//pulling out name and description only for the minute!!!
if ([[[node childAtIndex:counter] name] isEqual:#"name"]){
contact.name = [[node childAtIndex:counter] stringValue];
}else if ([[[node childAtIndex:counter] name] isEqual:#"description"]) {
// common procedure: dictionary with keys/values from XML node
if ([[node childAtIndex:counter] stringValue] == NULL){
contact.nextAction = #"No description";
}else{
contact.nextAction = [[node childAtIndex:counter] stringValue];
}
}else if ([[[node childAtIndex:counter] name] isEqual:#"created_at"]){
contact.date == [[node childAtIndex:counter] stringValue];
}else if([[[node childAtIndex:counter] name] isEqual:#"time_zone"]){
contact.status == [[node childAtIndex:counter] stringValue];
[res addObject:contact];
[contact release];
}
}
}
self.contactsArray = res;
[res release];
[self.tableView reloadData];
}
Thanks in advance for your help!!
Fiona
Might be a mistake but why are they double equals (==), usually used for a condition check