How to reduce code duplication in my Objective-C code?

I understand this is too broad a question, but I believe my Objective-C code is very repeatable. I think the function of the new blocks will help, but I still can’t assume that all my users are on iOS 4.

I often get two or three controllers with a lot of similar logic. I am pulling some of this logic into a common base class, but, especially with the code associated with the delegate, I find very similar logic happening in several different places due to slight differences.

For example, if I have a UITableViewController and I have several subclasses that use several identical rows, I can do little with inheritance. If a subclass adds an extra row (or several rows and / or if they are in the middle of the table and not at the end), indexing breaks and most delegate methods in the superclass no longer work - I have to redefine them in the subclass.

Again, I understand that this is vague, but what patterns should people ask for from the ascent?

Thank!

+5
source share
1 answer

You are using / thinking about the wrong design pattern.

Objective-C . , , , .

, UITableView , . datasource ( ). UITableViewController .

, / .

, UITableViewController , - , . , .

, , . , . , .

.

:

( / , ),

, tableView/datasource. , / . , . Core Data, . . .

tableview. .

Xcode Core Data. - , Core Data.

+3

All Articles