为什么 CLGeocoder 在调用时崩溃

Why does CLGeocoder crash upon call

我想将地址转换为 Mac 上的位置以用于路由目的。

我正在使用

[[CLGeocoder alloc] geocodeAddressString:@"1 Infinite Loop, Cupertino, CA 95014" 
                       completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
        if(error){
            NSLog(@"%@", error);
        }
        if(placemarks){
            NSLog(@"%@", placemarks);
        }
    }];

在运行时,执行崩溃并在代码片段的第一行显示 Bad Excess。 有没有人知道如何克服这个问题?

您需要初始化 CLGeocoder

CLGeocoder *geoCoder = [[CLGeocoder alloc] init];
[geoCoder geocodeAddressString:@"1 Infinite Loop, Cupertino, CA 95014"
             completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
                 if(error){
                     NSLog(@"%@", error);
                 }
                 if(placemarks){
                     NSLog(@"%@", placemarks);
                 }
             }];