ios - 从不兼容类型 'double*' 分配给 'double'

标签 ios database sqlite double

我有一个带有一些 double 类型字段的 SQLite 数据库,我必须提取这个值并将它们放在一个实例变量中,但是我得到了这个错误

  Assigning to 'double *' from incompatible type 'double'

这是代码:

数据库表.h

   @interface DatabaseTable : NSObject {
sqlite3 * database;

   }

   //........
   @property (nonatomic, assign)double *latitude; //latitude is a field of type double
   @property (nonatomic, assign)double *longitude; //longitude is a field of a type double

   @end

数据库表.m

   //.....
    while (sqlite3_step(statement) == SQLITE_ROW) {

       DatabaseTable * rowTable =[[ChinaDatabaseTable alloc]init];
           //.......

           rowTable.latitude =sqlite3_column_double(statement, 15); //here the error
           rowTable.longitude =sqlite3_column_double(statement, 16);//here the error

           //.....
     }

我能做什么?

最佳答案

您不需要在 int、float、bool 等原始类型之前放置 *

所以把代码改成这样:

   @property (nonatomic, assign)double latitude; //latitude is a field of type double
   @property (nonatomic, assign)double longitude; //longitude is a field of a type double

如果您需要创建一个指针变量,那么您的代码就可以了。

但是您不能将值直接分配给基本类型的指针值。

如果你需要分配地址值,你需要这样做:

double temp = sqlite3_column_double(statement, 15);
rowTable.latitude = &temp;

关于ios - 从不兼容类型 'double*' 分配给 'double',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13228230/

相关文章:

ios - TableViewController部分和行

ios - 无法滚动 MKMapView。

ios - Phonegap 应用程序中的 UserVoice 集成

mysql - 使用主键作为多个表的外键 -PHPMyAdmin

php - 内存泄漏或连接未关闭

mysql - 这些查询有什么区别?

sqlite - 通过NHibernate创建SQLite触发器

c# - 如何将 Objective-C 静态库绑定(bind)到 Xamarin.iOS?

android - 无法使用 SQLiteAssetHelper 打开数据库

android - 在 SQLite 中使用 strftime