-3

When I try to create an instance of a custom class, using this code...

PlayerTurn *playerTurn = [[alloc] init];

...inside the definition of a method in my View Controller .m file, I get this error:

"use of undeclared identifier alloc"

Can someone please explain!? I thought alloc-init was easy.

Jeremy
  • 1
  • 85
  • 340
  • 366
Dave
  • 81
  • 7

2 Answers2

1

alloc is a class method (on effectively all classes). You need to call it on the class you want to create an instance of. So you want :

PlayerTurn *playerTurn = [[PlayerTurn alloc] init];
//                         ^^^^^^^^^^
rickster
  • 124,678
  • 26
  • 272
  • 326
1

I think you meant:

PlayerTurn *playerTurn = [[PlayerTurn alloc] init];

The Working with Objects doc from Apple might be helpful.

Adam
  • 26,549
  • 8
  • 62
  • 79
  • 1
    I think I'll go ahead and shoot myself now. You should have an award in this site for most stupid question – Dave Dec 10 '15 at 22:11
  • @Dave Too bad there isn't a face-palm Emoji (though there may be one next year). – rmaddy Dec 10 '15 at 22:17