I recently started to wonder why we usually import .h files instead of .m files in Objective C.
#import ClassName.h
Is there any benefit on importing .h files over .m files?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The .m file is meant to be private, while the .h file is meant to be imported and used by other classes. For example, a small section of your .h file might look like this:
Your .m file on the other hand might look like this:
Classes that import your .h file and create an instance of your class will be able to directly access myPublicInteger and send messages to myPublicMethod. However, they will not have any access or knowledge of myPrivateInteger or myPrivateMethod.