gpt4 book ai didi

iphone - 初始化中不兼容的类型?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:52:13 24 4
gpt4 key购买 nike

为什么我在下面的代码中得到“初始化中不兼容的类型”?

NSString *latString = [NSString stringWithFormat:@"%@", @"-44.4349773"];
NSString *lngString = [NSString stringWithFormat:@"%@", @"-33.2779787"];
double latDouble = [latString doubleValue];
double lngDouble = [lngString doubleValue];
double roundDouble = 0;
NSNumber *mylngDoubleNumber;
if(latDouble == 0 && lngDouble == 0) {
NSNumber *mylngDoubleNumber = 0;
}else{
double tempDble = [self calcDiffDistance:latDouble withPostLng:lngDouble ]; <-- incompatible types...
NSNumber *mylngDoubleNumber = [NSNumber numberWithDouble:tempDble];



-(double)calcDiffDistance:(double )postLat withPostLng:(double )lon1 {

NSLog(@"beginning CLLocationDegrees in calcDiff in UsersPosts");
CLLocationDegrees lat = self.lastKnownLocation.coordinate.latitude;
CLLocationDegrees lng = self.lastKnownLocation.coordinate.longitude;
NSLog(@"finsished CLLocationDegrees in calcDiff in UsersPosts");

NSLog(@"beginning location1 in calcDiff in UsersPosts");
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:postLat longitude:lon1];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:-44.4343 longitude:-34.977];
NSLog(@"finsished CLLocationDegrees in calcDiff in UsersPosts");


NSLog(@"beginning location release in calcDiff in UsersPosts");
double target = [location1 distanceFromLocation:location2];
//int myInt = (int)ceil(target);
target = target/1609.334;
[location1 release];
[location2 release];
NSLog(@"finsished location release in calcDiff in UsersPosts");

return target;

.h 代码//////////////////////////////

                                                      #import <UIKit/UIKit.h>
#import "PostTableCustomCellController.h"
#import "LoadMoreResultsTableViewCell.h"
#include <stdlib.h>
#import "CLController.h"
#import <CoreLocation/CoreLocation.h>


@class PostDetailViewController;

@interface TransactionsTableViewController : UITableViewController <CLControllerDelegate, UIScrollViewDelegate, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate> {
IBOutlet UITableView *transactionsTableView;
NSMutableArray *postsArray;
PostDetailViewController *postDetailViewController;
UITableView *transTableView;
Boolean *isFetchingData;
int *webServiceAllCount;
NSCalendar *calendar;
NSTimer *minuteTimer;
NSTimer *regionsTimer;
Boolean *blockRefresh;
CLLocation *lastKnownLocation;
}

@property (nonatomic, retain) CLLocation *lastKnownLocation;
@property Boolean *blockRefresh;
@property (nonatomic, assign) Boolean *isFetchingData;
@property (nonatomic, retain) LoadMoreResultsTableViewCell *loadMoreResultsCell;
@property (nonatomic, assign) NSTimer *minuteTimer;
@property (nonatomic, assign) NSTimer *regionsTimer;


-(double)calcDiffDistance:(double )postLat withPostLng:(double )lon1;
- (NSString *)dateDiff:(NSString *)origDate;
- (void)updateTime:(NSTimer *)timer;
- (void)updateRegions;
-(void)newLocationUpdate:(CLLocation *)location;
-(void)newError:(NSString *)text;
@property (nonatomic, retain) UITableView *transTableView;
@property (nonatomic, retain) NSMutableArray *postsArray;
@property (nonatomic, retain) PostDetailViewController *postDetailViewController;

@end

最佳答案

在没有看到编译该代码的上下文的情况下,最好的猜测是您没有导入声明方法 calcDiffDistance:withPostLng: 的头文件。

此外,int* 类型的实例变量几乎肯定不是您的意思;你真的想要一个指向 int 的指针吗?!

这个方法名也有点粗糙:

-(double)calcDiffDistance:(double )postLat withPostLng:(double )lon1 {

这样的事情怎么样:

-(double)calculateDistanceFromLatitude:(double)lat longitude:(double)long

?

关于iphone - 初始化中不兼容的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5228916/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com