I am trying to call a method that returns an object and need help as I am getting a EXC_BAD_ACCESS when it is called. I am trying to get a QuoteMap object returned to the ViewController that calls it.
The method is addAndReturnQuoteMap which is as declared in the header QuoteMap.h
- (QuoteMap *)addAndReturnQuoteMap:(NSString *)subId withQuoteId:(NSString *)quoteId;
The method itself looks like this:
- (QuoteMap *)addAndReturnQuoteMap:(NSString *)subId withQuoteId:(NSString *)quoteId {
//FIRST GET A NEW QUOTE_MAP_ID
NSInteger newQuoteMapId = self.getNextQuoteMapId;
NSLog(@"newQuoteMapId = %d", newQuoteMapId);
// THEN TAKE THE QUOTE_MAP_ID, SUBJECT_ID AND QUOTE_ID AND INSERT INTO QUOTE_MAP TABLE
NSLog(@"subId = %@ quoteId = %@", subId, quoteId);
QuotesAppDelegate *appDelegate = (QuotesAppDelegate *)[[UIApplication sharedApplication] delegate];
FMDatabase *database = [FMDatabase databaseWithPath:appDelegate.getDBPath];
if ([database open]) {
[database executeUpdate:@"insert into QUOTE_MAP(quote_map_id, quote_id, subject_id) values(?, ?, ?)",
newQuoteMapId, subId, quoteId];
[database close];
}
[database open];
FMResultSet *result_categories = [database executeQuery:@"select * from QUOTE where quote_id = 835"];
[result_categories next];
QuoteMap *qm = [QuoteMap alloc];
qm.quote_map_id = [result_categories stringForColumn:@"QUOTE_MAP_ID"];
qm.quote_id = [result_categories stringForColumn:@"QUOTE_ID"];
qm.subject_id = [result_categories stringForColumn:@"SUBJECT_ID"];
qm.isDirty = NO;
NSLog(@"QuoteMap inserted the quote_map_id of: %@", qm.quote_map_id);
[qm release];
return qm;
};
I call the method from my AddQuoteViewController here:
[qm addAndReturnQuoteMap:mySubjectId withQuoteId:quote.quote_id];
I am sure there is something really stupid that I am doing wrong and would appreciate any direction on what that might me.
You’re not calling
initon yourQuoteMap. It should be:There is no case where you should call a bare
+allocwithout immediately calling some form of-init.