Generic Naming Conventions

I am writing a universal iOS application (iPad and iPhone) and am in massively long names for classes that cannot be shared between two applications:

FamilyViewController_iPhone.h/m FamilyViewControllerA_iPad.h/m DetailViewControllerB_iPhone.h/m DetailViewControllerB_iPad.h/m 

In addition, the classes inside these guys have a full name (including the device), so the Builder interface can easily use them.

I thought of something like AControllerA.h and BControllerA.h, where A = iPhone and B = iPad, but not happy with this option.

What is a conditional convention for classes like this in a universal iOS app, or am I (hopefully) missing something that eliminates this need?

+6
ios objective-c xcode naming-conventions universal-binary
source share
3 answers

I think you are going the wrong way, separating your functionality like that. While iPad apps may have different user interface structures and designs from your iPhone apps, it’s really better if you can try to stay as abstract as possible.

I avoid using platform names in my controllers. I would have:

 FamilyViewController.h FamilyViewController.m FamilyViewController.xib (which is used for the iPad UI) FamilyViewController~iphone.xib 

Most likely, you will have incredibly similar functionality for both the iPhone and iPad, or, if not the same, you will still have a lot of overlaps.

I also never have my view controllers be my table controllers. I keep this functionality in separate objects. Thus, if the iPhone application has 2 or 3 tables on different screens, but the iPad shows all 3 of these tables on one screen, you can simply create an instance of each of these table controllers, and all the code can be reused.

+4
source share

If you want to use the same YourClass with YourClass.xib and YourClass-iPad.xib, then check out this macro that I use:

 #define getXIB(s) ( (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? @"" #s "-iPad" :@"" #s ) 

So, you can use the class itself to get the corresponding XIB file:

 YourClass * viewController = [[YourClass alloc] initWithNibName:getXIB(YourClass) bundle:nil]; 
+2
source share

I'm not sure what the standard way to handle this.

One possibility is to use a cluster class strategy. If FamilyViewController_iPad and FamilyViewController_iPhone are very similar, make them subclasses of the abstract FamilyViewController class. Set the -initWithNibName: bundle: method to FamilyViewController so that it returns an instance of either the iPad or ... iPhone version, depending on which device the application is running on. In most of your codes, you will only deal with FamilyViewController. Of course, you still have to use the name of the subclass in your tips, but at least your code will be easier to read.

+1
source share

All Articles