r/simpleios • u/RightFootStar • Nov 09 '11
New to IOS development - Reading Programming Objective-c 2.0. Class Connection Question
Hey guys,
I'm new to the whole development thing. Just finished an accelerated web design course that was heavy on AS3 and OOP. Reading this book I have a good understanding of if, the methods and so on.
I'm struggling connecting classes and I'm making new file and basically I lost control of Xcode.
Any good reference links would be great. I will keep you guys posted on the game that I make.
8
Upvotes
View all comments
Show parent comment
1
u/easmussen Nov 09 '11 edited Nov 09 '11
In Xcode, if you make a new object (e.g. "Player") it should create both the .m (implementation) and the .h (header) files, and they will be 'connected' by default. To confirm this, you can look at the top of the .m file and it will say #import "Player.h". This means that the .m file will be aware of all the variable and method declarations in the .h file.
The header file is where you set the interface for the object, like a control panel on a black box. The .m file is where you program all the actual logic. But the .m file needs to be aware of its own interface, and that's why you import the .h file.
You can #import lots of different files as needed. For instance, if your Player class needs to access methods within a Game class, then you would add #import "Game.h" to the top of Player.m. So in practice, you'll have lots of these file 'connections' all over the place.