刚刚开始在Objective C中编程...指向接口对象的指针给出了分段错误
这段代码给了我一个段错误。它出什么问题了? 我知道它确实与“指令”有关。该阵列工作正常。
Instruction.h:
#ifndef romo_objectice_c_Instruction_h
#define romo_objectice_c_Instruction_h
#endif
#import <Foundation/Foundation.h>
typedef enum direction {north, south, west, east} Direction;
@interface Instruction:NSObject
@property Direction dir;
@property unsigned int distance;
@end
ViewController.m:
#import "Instruction.h"
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
@synthesize instructionList;
- (void)viewDidLoad {
[super viewDidLoad];
instructionList = [[NSMutableArray alloc] init];
//THE FOLLOWING CODE CAUSES THE SEGMENTATION FAULT
Instruction *i;
Direction d = north;
i.distance = 1;
i.dir = d;
[instructionList queuePush:i];
}
任何想法? 谢谢。
了解如何获取异常堆栈跟踪,以确定故障点。 – 2015-04-05 19:46:33