我想将MutableArray用于我在顶部通过以下代码宣布的任何方法

    @implementation STARTTRIP_1

    NSMutableArray *path = [NSMutableArray array];
...


但这是错误“ Initializer元素不是编译时常量”

我想使用此数组包含所有字符串。

    - (void)motionDetector:(SOMotionDetector *)motionDetector locationChanged:(CLLocation *)location
...

if (numberFormatter == nil) {
                numberFormatter = [[NSNumberFormatter alloc] init];
                numberFormatter.numberStyle = NSNumberFormatterDecimalStyle;
                numberFormatter.maximumFractionDigits = 6;
            }
            NSString *string = [NSString stringWithFormat:@"{%@, %@}",
                                [numberFormatter stringFromNumber:[NSNumber numberWithDouble:coordinate.latitude]],
                                [numberFormatter stringFromNumber:[NSNumber numberWithDouble:coordinate.longitude]]];
            [path addObject:string]; //HERE
            NSLog(@"%@",path);
...

最佳答案

我想您正在尝试创建static变量?

path中创建您的load,当类为first loaded时将调用该名称。

static NSMutableArray *path;

+(void)load
{
    [super load];
    path = [NSMutableArray array];
}

-(void)method
{

    // use path
}


坦白地说,我想您正在做一些令人讨厌的事情-为什么不使用propertyiVar

@implementation STARTTRIP_1 {
    NSMutableArray *_path;
}

-(instancetype)init
{
    self = [super init];
    if (self) {
        _path = [NSMutableArray array];
    }
    return self;
}

10-08 07:27