I want to load the table, see the value from a database that has been called for a test purpose database. Sqlite. This is populated with:
1, January
2, February
... to to ...
12 , December
As you will see that I am using FMDB, the following line is compiled but crashes:
NSString * myString = [[line item overindex : MyNumber] ObjectForreake: @ "Mahananam"]; I am part of your problem which is facing problems in dealing with insights and strings in Cocoa inconsistently. In addition, although there are NSLog debugging lines, The approach has become complicated. What can you advise me? NSArray * Path = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, Yes); NSString * docs path = [path objectitx: 0]; NSString * path = [docspath stringbappinging path: 'databases.sqlite']; FMDatabase * Database = [FMDatabase database path path:]; [Database open]; NSLog (@ "Open Database"); FMResultSet * Results = [Database Execution: @ "Select from Monthly"]; While ([result next]) {NSString * name = [result stringfar column: @ "name"]; NSInteger age = [Results intForColumn: @ "age"]; // array NSMutableArray * Rows in Straight Data = [[NSMutableArray alloc] init]; NSMutableDictionary * firstRow = [NSMutableDictionary dictionaryWithObjectsAndKeys: [NSNumber NumberAttention: age], @ "MonthID", [NSSTING stringweight format: @ "% @", name], @ "Mahananam", zero]; [Rows addObject: firstRow]; NSLog (@ "month:% @ -% d", name, age); Int myNumber = [[first line object foreaki: @ "month-end"] interview]; // *** I have problems in the following rows *** NSString * myString = [[Rows ObjectOutindex: MyNumber] ObjectForcae: @ "Mahananam"]; // NSLog (@ "Month number:% @ -% d", Mystring, MyNumber); NSLog (@ "***** month no:% d", MyNumber); // [Self. Glory math string]; } [Close the database]; NSLog (@ "Close Database");
This row returns the error because your index or month is starting at id 1 , But when you add it to the array:
[rows addObject: firstRow]; It is added to the 0 index (default starting index). So when you call this line:
NSString * myString = [[line of objectTitx: MyNumber] ObjectForekey: @ "Mahananam"]; This tries to remove the value at index 1. Because:
int myNumber = [[first line objectForcae: @ "monthday"] intValue]; It actually tries to extract value at index 1 which is not present because there is only 1 value on index 0 in your array, so it crashes.
EDIT: Try to use it: NSMutableArray * Rows = [[NSMUTABELARROL] INST]; While ([result next]) {NSString * name = [result stringfar column: @ "name"]; NSInteger age = [Results intForColumn: @ "age"]; NSMutableDictionary * firstRow = [NSMutableDictionary dictionaryWithObjectsAndKeys: [NSNumber NumberAttention: age], @ "MonthID", [NSSTING stringweight format: @ "% @", name], @ "Mahananam", zero]; // Array in Straight Data [Rows addObject: firstRow]; NSLog (@ "month:% @ -% d", name, age); Int myNumber = [[first line object foreaki: @ "month-end"] intValue] -1; // to get the value on the appropriate index ... // I have problems in the following rows *** NSString * myString = [[Rows ObjectOutindex: MyNumber] objectForKey: @ "Mahananama"]; // NSLog (@ "Month number:% @ -% d", Mystring, MyNumber); NSLog (@ "***** month no:% d", MyNumber); // [Self. Glory math string]; }
Comments
Post a Comment