The situation is the standard use of objective-c calling C and uploading the data back to Objective-c:
Defines a callback function in which Void*context int count is used to pass in the objective object, with the contents of the callback behind it.
So the callback function can be written as
typedef int (*player_callback) (void *opaque, int message, void *data, size_t data_size);
The basic use is as follows:
/* Sqlite_api int sqlite_stdcall sqlite3_exec (
sqlite3*,
const Char *sql,
Int (*callback) (void*,int,char**,char**),
void *,
Char **errmsg
);
*/
static int mycallback (void *context, int count, Char **values, char **columns)
{
Nsmutablearray *names = (__bridge Nsmutablearray *) context;
for (int i=0 i < count; i++) {
const char *namecstring = values[i];
[Names addobject:[nsstring stringwithutf8string:namecstring]];
}
return SQLITE_OK;
}
@implementation Mytableviewcontroller
-(void) loadnamesfromdatabase
{
NSString *file = [[NSBundle mainbundle] pathforresource:@ "names" oftype:@ "DB"];
Sqlite3 *database = NULL;
if (sqlite3_open ([File utf8string], &database) = = SQLITE_OK) {
Sqlite3_exec (Database, "SELECT name from Person", mycallback, names, NULL);
}
Sqlite3_close (database);
}