我想将MutableArray用于我在顶部公布的任何方法,并使用以下代码
@implementation STARTTRIP_1
NSMutableArray *path = [NSMutableArray array];
...
但是错误“初始化元素不是编译时常量”
我想使用这个数组来包含所有字符串。
- (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);
...
答案 0 :(得分:2)
我认为您正在尝试创建static
变量?
在path
中创建load
,因为当课程为first loaded时会调用此static NSMutableArray *path;
+(void)load
{
[super load];
path = [NSMutableArray array];
}
-(void)method
{
// use path
}
。
property
虽然老实说我觉得你做的事情有点讨厌 - 为什么不用iVar
或@implementation STARTTRIP_1 {
NSMutableArray *_path;
}
-(instancetype)init
{
self = [super init];
if (self) {
_path = [NSMutableArray array];
}
return self;
}
?
{{1}}