在Objective-C中获取指针变量的地址

时间:2012-10-25 01:42:28

标签: objective-c sqlite addressof

在sqlite3_open函数(Generic C函数)中,我需要发送sqlite3泛型C指针的地址作为参数。
例如:

//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.

问题是我需要从对象内部获取* db变量。 我知道这段代码是错的,但这是解释我需要的方法:

//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);

我希望有人陪我...哈哈哈 感谢您的时间! =)

1 个答案:

答案 0 :(得分:1)

假设MyClass看起来像这样:

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

您的代码将是:

MyClass * object = ... ;

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

object.database = database ;