Hashmat Khalil
Hashmat Khalil

Reputation: 1816

Is it all right to have multiple app delegates in the same project, for different targets?

I'm involved in developing an iOS app. The first thing that struck me was the multiple app delegates in the top level project, which has multiple target outputs. I do know that the sub-projects each have their own app delegate. I was told by my team members that those app delegates are used for different targets, but they have almost the same code, except that some variables are derived from a different class or sub-project. What are the pros and cons in having multiple app delegates in a project?

Upvotes: 4

Views: 2919

Answers (1)

justin
justin

Reputation: 104698

This structure is fine, if there is stuff in the app delegate that is actually different. If some of it is the same, consider how that code could be restructured (so you don't have duplicate code). Putting the common code in a superclass is one approach, but there are several others. Because subclassing is so strong, another approach is often preferable (e.g. composition).

One gotcha of the app delegate is that it can affect your resources -- i.e. if the class names differ, then you may be faced with minor differences in resources (e.g. NIBs) when these resources could just be identical.

Basic Rule of Thumb: If you find yourself facing duplicate code, find a way to avoid duplicating that code, or a way to remove that duplicate code in the event it's already been duplicated.

Upvotes: 5

Related Questions