I'm on a quest for knowledge today.
I'm working on some code for work, and after review I had a complete Brain Fart and can't remember why we do something with the .h and .m files in objective-c
Thanks everyone I hope that all made sense.
It's used to separate between the public and private parts of a class. The .m file is the implementation
. It is where all the logic goes, all the data is processed and stored, etc... The .h file is the interface
of that class. It's literally like an API for your own class. It tells other classes how to use it and how to interface with it.
You import a class when you reference it in a file. If you reference something (i.e. a property) in the interface then you import it in the .h. If you only reference it in the implementation then you import it in the .m.
Any methods declared in the .h are there so that other classes know that they can run it. i.e. they are public methods. Try and remove a declaration and then call that method. You'll get a warning.
No, this wouldn't make sense. Unless you were part way through writing your program and declared it for testing purposes.
Bonus extra for 2. In your .h file you should endeavour to have the minimum number of imports possible (just the superclass and any protocols you publicly implement) and use @class
for everything else. This minimises the dependency implications.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With