I’m migrating from C to Obj-C into Obj-C++. I’ll be taking my course in into to C++ for next semester. Hopefully, I’ll breeze through it.
So in Obj-C, private and public is determined by whatever you declare in your header file. Within a @interface of the .h file and all properties and instance/class methods that you can call on that class are laid out for you. From what I can assume about C++, I feel like public and private is in fact, all written out in the .h file: ivars, functions, what have you. Am I right in this assumption?
With earlier Objective-C compilers the
@interfaceof a class (often declared in the header file,.h) had to contain all data members (“ivars”). With the newer LLVM compiler it is possible to list them in the@implementation(.mfile).Other parts of Objective-C classes are not so restricted. Methods can be declared or defined in
.h,.m, both, or neither! Headers typically describe the methods that are most important, omitting things that are implementation-specific. Categories (a feature of the language) are a way to add new methods to a class while declaring and defining them somewhere else. There are also various ways to useNSObjectand the Objective-C runtime to do almost anything you can think of, e.g. deciding at runtime whether or not a class has a method, or adding a method, etc.