ios - identify iPhone 3, 4 and 5 in the same #define -


i've been using next line in constants differentiate between devices , number of device. what's appropriate way identify iphone 5 , still keep in 1 line format?

#define iphonetype [[uiscreen mainscreen] scale]==2 || [uidevice currentdevice].userinterfaceidiom == uiuserinterfaceidiompad ? @"4" : @"3" 

thanks

edit: lot of answers goal keep in 1 line format devices.

edit: based on comments, question needs clarification. here requirements:

  1. a single-line macro returns either @"3", @"4", or @"5" depending on ios device.
  2. the 4" devices (currently iphone 5 , 5th gen ipod touch) should return @"5".
  3. all ipads , remaining retina iphones , ipod touches should return @"4".
  4. all remaining non-retina iphones , ipod touches should return @"3".

assuming updated requirements correct, following should work:

#define iphonetype (fabs((double)[uiscreen mainscreen].bounds.size.height - (double)568) < dbl_epsilon) ? @"5" : ([uiscreen mainscreen].scale==2 || ui_user_interface_idiom() == uiuserinterfaceidiompad ? @"4" : @"3") 

this return @"5" 4" screened iphones , ipod touches. return @"4" ipads , retina iphones , ipod touches. , return @"3" non-retina iphones , ipod touches.


Comments