Reputation: 13
I am new at programming in general (though I have had a C class many, many years ago) and am learning Objective-C for programming on the iPhone. I have what I think is a simple question, but after looking for a while (days, off and on) I can't find the answer that I'm looking for explicitly.
I know that when subclassing an Objective-C class I should implement the initialize method along with the deallocate method (unless using ARC for the latter, if I am correct?). The questions are:
Thanks for your help!
Upvotes: 1
Views: 1336
Reputation: 726569
init
and dealloc
if the inherited versions are sufficient. Also, ARC does not free you from having to write dealloc
in all cases (but it certainly covers the overwhelming majority). For example, if you allocate memory for your object using malloc
, you need to free it in the dealloc
.@requried
. These methods are marked in the protocol reference. For example, tableView:cellForRowAtIndexPath:
and tableView:numberOfRowsInSection:
are marked with the "required method" tag in Apple's documentation.Upvotes: 3
Reputation: 14886
No methods are required when subclassing an NSObject (or any of their subclasses, such as UIViewController, UIView, etc. etc.).
If you create a new, let's say UIViewController, it's generally a good idea to keep the methods you find in the newly created file as a guideline/template, but you're not really required to keep any of the methods. The super class will always call the methods on itself.
Be aware, though, some methods you have to call super, like viewWillAppear, etc.
Upvotes: 0