Is there a method that is always called in Cocoa? Many classes have init or initWith, but even worse they can be loaded from a nib or something. I don’t want to have to scrape around and find how it does this in this case. I just want to set some initial variables and other things, and I want a method to subclass that I can depend on no matter if it’s a UIView, UIViewController or UITableViewCell etc.
Is there a method that is always called in Cocoa? Many classes have init
Share
No there is not such a method.
initcomes fromNSObjectso every object can use it, and as well subclasses define their own initialization methods.UIView, for example, definesinitWithFrame:and furthermore there are init methods from protocols, such asNSCodingwhich definesinitWithCoder:. This is the dynamic nature of objective-C, anything can be extended at any time. That being said, there are some patterns.UIViewControlleralmost always takesinitWithNibName:bundle:andUIViewalmost always takesinitWithFrame:orinitWithCoder:. What I do is make an internal initialize method, and just have the other inits call it.