2015-09-28 39 views
-1

我有这样的方法,以便:Objective-C的参数“双*”

-(void)insertTracking:(NSString *)tag deviceId:(NSString *)phone latitude:(double *)latitudeId longitude:(double *)longitudeId Completetion:(void (^) (NSArray * result,NSError * error))completion{ 

} 

,给了我这样的警告:

Format specifies type 'double' but the argument has type 'double *' 

,这是怎么了调用它:

[self insertTracking:barcodeHolder deviceId:[[UIDevice currentDevice] name] latitude:currentLocation.coordinate.latitude longitude:currentLocation.coordinate.longitude Completetion:^(NSArray *results, NSError *error){ 

}]; 

,我得到这个错误

Sending 'CLLocationDegrees' (aka 'double') to parameter of incompatible type 'double *' 

变量的经度和纬度来自CLLocation如何将它们传递给double?当我将它们作为字符串插入时,它们会插入到我的数据库中,因为0请帮助,我不明白我做错了什么。

+0

'insertTracking:deviceId:等等:'你自己的方法?你的主要问题是这个方法期望一个'double *'并且你给它一个'double'(注意“*”的存在/不存在)。 – Larme

+0

从您的方法中删除*。 – ErasmoOliveira

回答

3

这些参数应该是double,而不是double *,假设它们是输入参数。除非用于输入/输出或输出,否则通过指针传递基元类型非常罕见。

-(void)insertTracking:(NSString *)tag 
      deviceId:(NSString *)phone 
      latitude:(double)latitudeId 
      longitude:(double)longitudeId 
     Completetion:(void (^) (NSArray * result,NSError * error))completion; 

(注知道为什么你在自己的名字的时候买的Id;这是混淆)。