Problem with using classes

Discussion in 'iOS Programming' started by D.A.N., Mar 2, 2009.

  1. macrumors newbie

    Mar 2, 2009
    My problem here is that I have created 2 classes. One called Object, of which there will be multiple instances created, holding coords, and a few other bits of information about the object, and another called level. This one will be used to create and manage these instances.

    #import "Object.h"

    @implementation Object

    -(void) Create {

    coordx = 0;
    coordy = 0;
    active = 0;
    turndirection = 0;


    and this is level.

    #import "Level.h"
    #import "Object.h"

    @implementation Level

    Object *myObj = [[Object alloc] init];

    Pretty basic at the moment but I've just started out. My problem is just after creating the new instance of Object I get an error saying "Initializer element is not constant".

    What am I doing wrong here?
  2. Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    You need to put the following line in a method within the Level class:
    Object *myObj = [[Object alloc] init];
    Or you can define it as static, like so:
    static Object *myObj = [[Object alloc] init];

Share This Page