I'm writing a universal iOS application (iPad and iPhone) and find myself with massively long names for classes that can't be shared between the two apps:
FamilyViewController_iPhone.h/m
FamilyViewControllerA_iPad.h/m
DetailViewControllerB_iPhone.h/m
DetailViewControllerB_iPad.h/m
And likewise, the classes inside of these guys have the complete name (device included) mainly so that Interface Builder can easily use them.
I considered something like AControllerA.h and BControllerA.h where A=iPhone and B=iPad but not excited about that option either.
What is the standing convention for classes like this in an iOS universal application - or am I (hopefully) missing something that obviates this necessity?
I think you're heading down a bad path by separating your functionality like this. While iPad apps can obviously have different UI structures and design from your iPhone apps, but it's really best if you can try to remain as abstract as possible.
I avoid using platform names in my view controllers. I'd have:
FamilyViewController.h
FamilyViewController.m
FamilyViewController.xib (which is used for the iPad UI)
FamilyViewController~iphone.xib
You're most likely going to have incredibly similar functionality for both iPhone and iPad, or if not the same, you'll still have a lot of overlap.
I also never make my view controllers act as my table controllers. I keep that functionality in separate objects. That way, if the iPhone app has 2 or 3 tables on different screens, but the iPad shows all 3 of those tables on the same screen you can just instantiate each of those table controllers and all of the code is reusable.
If you want to use the same class 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 then use the class itself to get the proper XIB file:
YourClass * viewController = [[YourClass alloc] initWithNibName:getXIB(YourClass) bundle:nil];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With