game.h file
@interface ViewController : UIViewController
{
UIImageView * player;
}
@end
game.m
-(void)InitPlayer
{
player.tag = 0;
}
player.m
I want InitPlayer in this file instead but keep declaration in game.h file.
- (void)InitPlayer
{
player.tag = 0; // access UIImageView *player;
}
Is this possible to do?
Thanks
just use this to declare
-InitPlayerpart of your class’ public interface:then you keep your implementation of
-InitPlayerin ViewController.m, where it must reside. You cannot place the method’s implementation inside an@interfaceblock.if you are coming from other languages, then you should know that dispatch in objc is dynamic — placing a definition in the header (if it were possible) would not result in an inlined/optimization.
In response to the clarified question:
Ok, then just do this:
Player.h
Player.m
then you can tell the Player to initialize the view from the
ViewController, assuming it has no controller itself.(note: objc methods names typically begin with a lowercase character. as well, it’s usually a good idea to hide this initialization stuff from your clients)