Logan Serman
Logan Serman

Reputation: 29860

Using a custom class within another custom class in Objective-C

I have a custom class Manager in Xcode. This class spawns several instances of class Player on a timer, so every tick of the timer it will make a new instance. I would like to pass the instance of Manager to each instance of Player through Players init method:

-(id)initWithMngr:(UIImage *)image andManager:(Manager *)mngr

Here I get the error "expected a type." with or without the asterisk. The Manager class is in the same project and everything but I don't understand how to do this. I am very new to Objective C, thanks :)

Upvotes: 0

Views: 138

Answers (1)

kpower
kpower

Reputation: 3891

You should add either #import "Manager.h" or @class Manager; to your file, where interface of Player class is defined - possibly, "Player.h". (Here I suppose that your Manager class interface is defined in "Manager.h" file and Player - in "Player.h".)

If you will choose variant with @class Manager, don't forget to add #import "Manager.h" to your Player's implementation file (suppose, "Player.m").

Upvotes: 1

Related Questions