xcode4.6 - iOS Universal App Class Architecture -


what correct way implement classes in universal app?

i have 2 xib (one each device), each xib calls same class , inside class have conditional statement checking type of device running app , corresponding code each one.

i'm confused if correct structure, or have create base class , extend class each of devices overwrite corresponds each one?

i try reuse code can many developers create separate classes iphone , ipad versions avoid "spaghetti code". depends on complexity of app writing. if it's simple app see no reason provide logic test device , execute different code based on vs creating multiple classes each. although, there many benefits creating separate code each such unit testing or easy updating of ipad specific code , vice versa. have seen successful developers use both methodologies , both work if document , pragma mark code correctly.

here example of using diff classes

you can create simple class returns device type if typing out full test bothers people. handy if want test things ipod , other device types. times not approach use unless project large , classes begin feel cluttered.

// testdevice.h @interface testdevice : nsobject  + (bool)isipad;  @end  // testdevice.m #import "testdevice.h"  @implementation testdevice  + (bool)isipad {     if (ui_user_interface_idiom() == uiuserinterfaceidiompad)         return yes;      return no; }  @end 

then add .pch , can reuse anywhere in app calling...

if ([testdevice isipad]) {     // } else {      // else } 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -