Get Address of Pointer Variable in Objective-C

497 views Asked by At

In the sqlite3_open function (Generic C function), I need to send the address of the sqlite3 generic C pointer as an argument.
Example:

//Valid code
NSString * databaseFile; //Path of database file. (Objective-C Object)
sqlite3 * db; //Pointer to hold the sqlite database. (C Pointer)

sqlite3_open([databaseFile UTF8String], &db); //db is sent using the & operator.

The problem is that I need to get *db variable from inside an object. I KNOW this code is wrong, but it is a way to explain what I need:

//I need to get the address of the pointer 'database' from inside the Objective-C Object 'object'.
//I hope one of those wrong lines explain what I want:

sqlite3_open([databaseFile UTF8String], &[object database]);
sqlite3_open([databaseFile UTF8String], [object &database]);
sqlite3_open([databaseFile UTF8String], &(object->database);

I hope someone undertands me... Hahaha Thank you for your time! =)

1

There are 1 answers

0
nielsbot On BEST ANSWER

Assuming MyClass looks like this:

@interface MyClass : NSObject
...
@property ( nonatomic ) sqlite3 * database ;
...
@end

Your code would be:

MyClass * object = ... ;

sqlite3 * database ;
sqlite3_open( ..., & database ) ;

object.database = database ;