lundi 21 mars 2016

How implement custom dictionary in objective C

I want to create an ios application. I have a text file of common words(~100k). I want to create a new custom dictionary that includes this words.

This dictionary need to run in my ios application that will select/sort/find/delete/add a full/part of the words.

What is the best way to implement it? It must be fast.(my sqlite is very slow implementation).

-(NSMutableArray*) numOfWordsFrom:(NSString *) type Containes:(NSString*)parOfWord{

sqlite3_stmt    *statement;
NSInteger sum = 100001;
NSInteger var = 0;
NSMutableArray *arr = [[NSMutableArray alloc] initWithCapacity:1];
    if(sqlite3_prepare_v2(MyDB, [[NSString stringWithFormat: @"SELECT min(rowid),word FROM %@  where Word GLOB '%@*' limit 1",type,parOfWord] UTF8String], -1, &statement, NULL) == SQLITE_OK)
    {

        if (sqlite3_step(statement) == SQLITE_ROW)
        {
            sum = sqlite3_column_int(statement, 0);
            if (sum > 0) {
                if ([[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)] isEqualToString:parOfWord]) {
                    var = 1;
                }else
                    var = 2;

            }
        }

    }else
    {
        NSLog(@"Failed to Prepare Sensor:%@ Read last data ",type);
    }
    sqlite3_finalize(statement);
    //  }


    [arr addObject:[NSMutableArray arrayWithObjects:[NSNumber numberWithInt:var],[NSNumber numberWithInt:sum],nil]];
}
return arr;

}

Thanks

Aucun commentaire:

Enregistrer un commentaire