预期标识符或;(“CLO”在Xcode 5中的位置

预期标识符或;(“CLO”在Xcode 5中的位置,xcode,cllocationmanager,Xcode,Cllocationmanager,我正在构建我的第一个应用程序,我不知道这是否是一个bug,也不知道问题在哪里。我已经检查了SO和goog几个小时,但无法跟踪这个特定的修复。非常感谢您的帮助 ViewController.h #import "AppDelegate.m" #import "CoreLocation/CoreLocation.h" #import "MapKit/MapKit.h" @interface ViewController : UIViewController @end @interface C

我正在构建我的第一个应用程序,我不知道这是否是一个bug,也不知道问题在哪里。我已经检查了SO和goog几个小时,但无法跟踪这个特定的修复。非常感谢您的帮助

ViewController.h

#import "AppDelegate.m"
#import "CoreLocation/CoreLocation.h"
#import "MapKit/MapKit.h"


@interface ViewController : UIViewController 
@end

@interface CLLocationManagerDelegate : CLLocationManager
@property (strong, nonatomic) CLLocationManagerDelegate *locationManager;
@end
ViewController.m

#import "ViewController.h"


@implementation ViewController;
- (IBAction)Parked:(id)sender {
}
- (IBAction)WheresMyCar:(id)sender {
}
@end


@implementation CLLocationManagerDelegate;
{ **error is here, expected identifier or )**

-   (void)startStandardUpdates
if (nil == locationManager)
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
locationManager.distanceFilter = 250;
[locationManager startUpdatingLocation];


-(void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
//recent event, turn off updates to save power
CLLocation* location = [locations lastObject];
NSDate* eventDate = location.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
//if event is recent, do something with it
if (abs(howRecent) <15.0) {
    NSLog(@"latitude %+.6f, longitude %+.6f\n",
          location.coordinate.latitude,
          location.coordinate.longitude);
}
}


- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

}
@end
#导入“ViewController.h”
@实现视图控制器;
-(iAction)已驻车:(id)发件人{
}
-(iAction)其中mycar:(id)发送方{
}
@结束
@实施CLLocationManagerDelegate;
{**此处有错误,应为标识符或)**
-(无效)开始和结束更新
if(nil==位置管理器)
locationManager=[[CLLocationManager alloc]init];
locationManager.delegate=self;
locationManager.desiredAccuracy=KCallocationAccuracykilometer;
locationManager.distanceFilter=250;
[locationManager startUpdatingLocation];
-(无效)locationManager:(CLLocationManager*)经理
didUpdateLocations:(NSArray*)位置{
//最近事件,关闭更新以节省电源
CLLocation*location=[locations lastObject];
NSDate*eventDate=location.timestamp;
NSTimeInterval howRecent=[eventDate timeIntervalSinceNow];
//如果事件是最近发生的,请对其进行处理

如果(abs(hownewest)对不起,这个代码有很多问题

@implementation CLLocationManagerDelegate;
@implementation ViewController;
的末尾删除
,并从
@implementation ViewController;{
}@end
中删除
{code>}

此方法
-(void)startStandardUpdates
也缺少
{}
括号替换

- (void)startStandardUpdates
{
    // if(nil == locationManager) This is just silly change to below
    if (locationManager == nil) 
        locationManager = [[CLLocationManager alloc] init]; // Because there are no {} wrapping this if statement this is the only line that will run if locationManager is nil

    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
    locationManager.distanceFilter = 250;
    [locationManager startUpdatingLocation]; 
}
旁注

当谈到约定时,a方法应该以小写字母声明,所以下面的方法

- (IBAction)Parked:(id)sender { }
- (IBAction)WheresMyCar:(id)sender { }
应该成为

- (IBAction)parked:(id)sender { }
- (IBAction)wheresMyCar:(id)sender { }
由于您的子类化
CLLocationManager
我不建议使用名称
CLLocationManagerDelegate
,这可能会造成一些混乱。我建议使用类似于
@接口LocationManager:CLLocationManager
的方法,或者在其前面加上其他类似公司首字母的前缀,以便我为其工作的公司将成为
@interface PPDLocationManager:CLLocationManager
,这也是您不应该像类那样使用名称
CLLocationManagerDelegate
的原因,因为它已经是协议名称请参见

以下方法在错误的
@实现中

- (void)viewDidLoad
- (void)didReceiveMemoryWarning

它们应该在您的
ViewController
实现中,而不是
CLLocationManagerDelegate
实现中。

错误行上的
{
应该在方法名称
startStandardUpdates
之后。但是您确定要创建CLLocationManager的子类并使用该名称吗“CLLocationManagerDelegate”用于该子类?谢谢大家:)我已将其安装并运行…现在调整它。