Question: I usually declare the rects & colours in static const format in my view controllers like this for example. (these are compile time)

```
#import "something.h"

static const CGRect someRect = { w, x, y, z };
static const uint8_t someColor[] = { 255, 0 , 0}

@implementation

// other methods

@end

```

This way **doesn't work very well** when it comes to device specific scenarios. For example if I want to make the rect a bit higher for **iPhone5 & iPod Touch 5th generation** there is no way to determine this in compile time. (for iPhone 5 may be we can add pre processor macro in build settings for armv7s architecture -> img below), but for iTouch the architecture is armv7 & this would clash with iPhone4S as well, also if Apple were to release new devices with mixed size screens in same architecture in future, this approach is literally screwed. 

![preprocessor macro](https://i.stack.imgur.com/ri8UY.png)

My question is what would be a workaround / a fix or alternative to this. ? I'll also list down few things in mind but I'd like to know your opinion & best practices for doing something like this. 

1 - do it the same way assuming its for the older 320x480 device and make the UI elements expand or grow ( autoresizingmask ) as it gets the correct screen size assigned in runtime. 

2 - use +initialize() method, this would be runtime (contrast to compile time in original approach) but you will have access to all the sophisticated methods to find the screen size & device types. 

or some other way(s) because all methods above are stupid.

Answer: 
Don't try to detect the device at compile-time, that's impossible. You can't know in advance what kind of device your code will run on, since as you said, Apple could release future iOS devices running on armv7s with different hardware characteristics from the iPhone 5/iPod 5.

Instead, you need to detect the device type at runtime and then take appropriate actions. Since certain features such as the screen size won't be known until runtime, then obviously they can't be compile-time constants, so you'll need to restructure your code accordingly.

Ideally, you shouldn't be trying to detect specific \*device types and then act based on that; instead, determine which *features* you have/need, and act on that. For example, get the screen size at runtime instead of hard-coding several devices' different screen sizes. Detect if you have a camera, and then decide to take a photo based on that, etc. Detect if the device supports OpenGL ES v2.0, then change your rendering code based on that. And so on.

But if you really do need to detect the specific device model, [this question](https://stackoverflow.com/questions/448162/determine-device-iphone-ipod-touch-with-iphone-sdk) has several answers showing you how.
I agree with Adam for detecting features, however, what I like to do is define constant sizes and positions in relative terms:

```
#define SOMERECT_X 0.25
#define SOMERECT_Y 0.25
#define SOMERECT_W 0.5
#define SOMERECT_H 0.5

```

Then when it comes time to set up, for example someRect:

```
CGRect someRect = 
    CGRectMake(self.view.bounds.size.width * SOMERECT_X,
    self.view.bounds.size.height * SOMERECT_Y,
    self.view.bounds.size.width * SOMERECT_W,
    self.view.bounds.size.height * SOMERECT_H);

```

This example uses the view's bounds, but you could substitute another constant value (e.g., screen size).