views:

45

answers:

1

Here is my plist:

<dict>
 <key>ehindi</key>
 <string>ankamaal</string>
 <key>part</key>
 <string>n</string>
 <key>meaning</key>
 <string>hug</string>
 <key>hindi</key>
 <string>अंकमाल </string>
</dict>

Here is my code:

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSString *finalPath = [path stringByAppendingPathComponent:@"Data.plist"];
    NSDictionary *plistData = [[NSDictionary dictionaryWithContentsOfFile:finalPath]
        retain];

    NSArray *inHidi = [NSArray arrayWithArray:[dict valueForKey:@"hindi"]];
    NSDictionary *inHindiDict = [NSDictionary dictionaryWithObject:inHindi    
        forKey:@"HindiArray"];

    NSArray *inEhindi = [NSArray arrayWithArray:[dict valueForKey:@"ehindi"]];
    NSDictionary *inEhindiDict = [NSDictionary dictionaryWithObject:inEhindi 
        forKey:@"EHindiArray"];

    [listItem addObject:inEhindiDict];
    [listItem addObject:inHindiDict];

    copyItem = [[NSMutableArray alloc] init];

    /////....
}

I'trying to search key 'ehindi' and display 'hindi' result on my screen. Here What i did to search

 - (void) searchTableView {
     NSString *searchText = searchBar.text;
     NSMutableArray *searchArray = [[NSMutableArray alloc] init];

     for (NSDictionary *dictionary in listItems)
     {
         NSArray *array = [dictionary objectForKey:@"EHindiArray"];
         [searchArray addObjectsFromArray:array];
     }

     for (NSString *sTemp in searchArray)
     {
         NSRange titleResultsRange = [sTemp rangeOfString:searchText 
             options:NSCaseInsensitiveSearch];

        if (titleResultsRange.length > 0)
            [copyItem addObject:sTemp];
     }

     [searchArray release];
     searchArray = nil;
 }

I am just able to search 'ehindi'. How can i find the and display the word in 'hindi'. It is not possible to search devnagari and only option I have is to find the index and dispay the value of that index of "EHindiArray".... I will be really happy if someone could help me to solve this problem.

A: 

I am not an expert in Objective-C. The way you are asking your question "Searching on array and displaying the value of another at the same index" sounds like these are parallel arrays.

Can you not simply store the index of the one array and use that variable to display the value of the other?

I may misunderstanding how the plist comes into play here but...

On the other hand, it looks like you are creating a dictionary. Why use the dictionary object for this? You could make your own custom HindiWord class and have strings for each of your dictionary entries. It would be something like:

#import <Foundation/NSObject.h>

@interface HindiWord: NSObject {
    NSString ehindi;
    NSString part;
    NSString meaning;
    NSString hindi;
}

@end

You'd then have 1 array of these objects, and you could search for the ehindi string, and easily grab the hindi string.

Tylo