简体   繁体   English

ARC不允许将Objective-C指针隐式转换为'const char *'?

[英]Implicit conversion of an Objective-C pointer to 'const char *' is disallowed with ARC?

This is my code: 这是我的代码:

//--   check for d/b; create it if it doesn't exist
NSString *docsDir;
NSArray *dirPaths;

NSMutableArray *sqliteArray = [NSMutableArray array];
[sqliteArray addObject: @"CREATE TABLE IF NOT EXISTS SiteData (SITE_ID TEXT PRIMARY KEY NOT NULL, STA1 TEXT "
    "TBM TEST, SITE_DESC TEXT, REMARKS TEXT, LOOP_COUNT INTEGER, DATE TEXT)" ];
[sqliteArray addObject: @"INSERT INTO SiteData (SITE_ID, LOOP_COUNT) VALUES('','')"];
[sqliteArray addObject: @"CREATE TABLE Readings (SITE_ID TEXT REFERENCES SiteData, LOOP_NBR TEXT, LOOP_CLOSED BINARY, "
    "SEQ INTEGER, STA TEXT, BS TEXT, FS TEXT, DESC TEXT, SSBS TEXT, SSFS TEXT)" ];
[sqliteArray addObject: @"INSERT INTO Readings (SITE_ID, SEQ) VALUES ('','')"];
[sqliteArray addObject: @"CREATE TABLE EmailAddress (EMAIL_ADDRESS TEXT)"];
[sqliteArray addObject: @"INSERT INTO EmailAddress (EMAIL_ADDRESS) VALUES ('Enter email address here')" ];


//  get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
docsDir = [dirPaths objectAtIndex: 0];

//  build path to the d/b file
databasePath =[[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"r64.sdb"]];
NSFileManager *filemgr = [NSFileManager defaultManager];

if([filemgr fileExistsAtPath:databasePath] == NO)  {
    const char *dbpath = [databasePath UTF8String];
    if(sqlite3_open(dbpath, &dbLevelingData) == SQLITE_OK) {
        char *errMsg;
        int i;

        for(i = 0; i < [sqliteArray count]; i++)  {
        if(sqlite3_exec(dbLevelingData, [sqliteArray objectAtIndex:i] , NULL, NULL, &errMsg) != SQLITE_OK)  
            status.text = @"Failed to create table";
        }

        sqlite3_close(dbLevelingData);
    }
    else 
        status.text = @"Failed to open/create database";
}

On the "if(sqlite3_exe..." statement, I'm getting the following build error: 在“if(sqlite3_exe ...”语句中,我收到以下构建错误:

Implicit conversion of an Objective-C pointer to 'const char *' is disallowed with ARC

Why (I don't see any 'const' char)? 为什么(我没有看到任何'const'char)? and how do I fix it? 以及如何解决? (note: I copied the basic format from another example... the NSMutableArray does NOT have to be mutable, if that would help things) (注意:我从另一个例子中复制了基本格式...... NSMutableArray不一定是可变的,如果那样会有所帮助)

According to this page , sqlite3_exec() is defined as such: 根据这个页面sqlite3_exec()定义如下:

int sqlite3_exec(sqlite3*,const char *, int (*)(void*,int,char**,char**), void *, char **);

However, you are invoking it as: 但是,您将其调用为:

int sqlite3_exec(sqlite3 *, id, int(*)(void *)(void *, int, char**, char **), void *, char **);

So, if you change your function call to this: 因此,如果您将函数调用更改为:

sqlite3_exec(dbLevelingData, [[sqliteArray objectAtIndex:i] UTF8String], NULL, NULL, &errMsg)

Your code should work fine (basically, we are converting your NSString into a const char * ). 您的代码应该可以正常工作(基本上,我们将您的NSString转换为const char * )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TPMultiLayoutViewController的ARC转换; ARC不允许将Objective-C指针隐式转换为“ const void *” - ARC conversion of TPMultiLayoutViewController; Implicit conversion of an Objective-C pointer to 'const void *' is disallowed with ARC ARC 不允许将 Objective-C 指针隐式转换为“void *” - implicit conversion of an Objective-C pointer to 'void *' is disallowed with ARC 从Objective-C指针到int *的隐式转换不允许使用ARC - Implicit Conversion from Objective-C Pointer to int * is Disallowed With ARC ARC不允许对Objective-C指针进行隐式转换 - Implicit conversion of an Objective-C pointer is disallowed with ARC 错误:在NSTimer选择器中,ARC无法将Objective-C指针隐式转换为&#39;SEL _Nonnull&#39; - Error : Implicit conversion of an Objective-C pointer to 'SEL _Nonnull' is disallowed with ARC in Selector Of NSTimer 使用ARC-sqlite3不允许将Objective-C指针隐式转换为'void *' - implicit conversion of an Objective-C pointer to 'void *' is disallowed with ARC - sqlite3 将属性移动到.h文件后,ARC不允许将Objective-C指针隐式转换为“ int *” - Implicit conversion of an Objective-C pointer to 'int *' is disallowed with ARC after move property to .h file 在 Objective-C 中,arc 不允许将 int 隐式转换为 NSString - implicit conversion of int to NSString is disallowed with arc in Objective-C ARC 不允许目标 c 类型指针“CFDataRef”的隐式转换? - implicit conversion of objective c type pointer 'CFDataRef' is disallowed with ARC? 使用ARC隐式转换指向objective-c指针的间接指针 - implicit conversion of an indirect pointer to an objective-c pointer with ARC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM