Objective c 指向接口对象的指针导致分段错误

Objective c 指向接口对象的指针导致分段错误,objective-c,Objective C,刚开始在目标C中编程 这段代码给了我一个分段错误。怎么了? 我确信这与教学有关。阵列工作正常 说明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} Di

刚开始在目标C中编程

这段代码给了我一个分段错误。怎么了? 我确信这与教学有关。阵列工作正常

说明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
有什么想法吗? 谢谢。

您没有所需的@implementation for指令。在开始尝试使用i变量之前,也不会创建实例


我不确定什么是queuePush,但这也可能会导致问题…

好的,我假设这就是我创建实例的方式:指令*I=[[Instruction alloc]init];你能告诉我头文件对@implementation有什么要求吗?实际上不清楚你是否没有用于指令的@implementation。显示的两个文件是Instruction.h和ViewController.m。指令的实现通常在指令.m中,但没有显示。假设它存在并包含正常的内容,那么无法创建指令实例并指出它可能是唯一的问题。是的,您在上面的评论中展示的代码片段是如何实例化指令实例的。谢谢。我没有指导。有必要有指导吗?我不打算在教学中有任何作用。只是实例变量。是的,您需要在某个地方合成属性。它可以是空的@implementation@end,但必须存在。了解如何获取异常堆栈跟踪,以确定故障点。
    #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];
}