我有一个名为的函数:- (void) AddSortedCustomFeed :(NSMutableArray*) rssList;
这个函数将 sqlite 数据库中的项目(文章)添加到NSMutableArray
这里这个函数是如何工作的:
- (void) AddSortedCustomFeed :(NSMutableArray*)rssList {
NSLog(@"\n\n\n ----- Add Sorted SQL Database -----");
NSLog(@"Start");
// Create Query String.
NSString* sqliteQuery = [NSString stringWithFormat:@"SELECT mainLink, title, summary, pubDate, author, imageLink, body, favorites, pubdatetime FROM ARTICLES WHERE customfeed = 'Y' ORDER BY pubdatetime DESC"];
NSLog(@"Query String is: %@", sqliteQuery);
// Pointer to Article and Statement.
Article* article;
sqlite3_stmt* statement;
// Prepare SQL for work.
if( sqlite3_prepare_v2(articlesDB, [sqliteQuery UTF8String], -1, &statement, NULL) == SQLITE_OK ) {
// Get next row from database.
while( sqlite3_step(statement) == SQLITE_ROW ) {
// Alloc and init article.
article = [[Article alloc] initWithValues:[NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 1)]
mainLink:[NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 0)]
summary:[NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 2)]
pubDate:[NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 3)]
author:[NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 4)]
imageLink:[NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 5)] ];
//article.body = [NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 6)];
NSString* favo = [NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 7)];
article.favorite = [favo hasPrefix:@"N"] ? NO : YES;
// Add to list.
[rssList addObject:article];
// Release article.
[article release];
}
}
else NSLog( @"SortSQLDatabase: Failed from sqlite3_prepare_v2. Error is: %s", sqlite3_errmsg(articlesDB) );
// Finalize and close database.
sqlite3_finalize(statement);
NSLog(@"End\n\n\n");
}
您如何在这个函数中看到我创建文章Article* article;
和在 while 循环中分配并初始化它。之后我将 Article 对象添加到NSMutableArray
然后释放它,但是我调用[article release];
了女巫必须调用它不调用的 delloc 函数?我不明白为什么。我尝试不同的方式,但我所有的尝试都崩溃了。这是关于文章类的文章-链接