IOS CS193p - Why was an IBAction connection dragged into a .m file and not into .h?

I noticed that in the demo version of the calculator for Stanford CS193p, the IBOutlet connection was dragged from the label to the header file. However, an IBAction connection was directly created in the .m file. I tried to read the documentation and search on Google, but could not find the reason for this.

I would say that the IBAction digitPressed method should also be declared in the header file (should it not be part of the interface?).

I'm obviously pretty new to Objective-C (mostly working in Java), so I'm sure I'm missing something.

Can someone explain?

+6
source share
1 answer

Declaring things in the class header file makes them part of the public interface. This includes the outputs and actions defined on the view controller.

Whether something should be published is a design issue. A good leader is: only if necessary. With points and actions of ViewControllers, they do not have to be - and therefore do not have to be public.

What usually happens is that you make some guesses about what the public interface should contain, and then (if you are a tidy developer), you again look at when the implementation has matured and delete something immaterial.

+8
source

Source: https://habr.com/ru/post/912351/


All Articles