1

I'm using iOS SDK 4.2.

I think that the ternary conditional op is(?) implemented differently on the simulators (iPhone4.1, 4.2. iPad 3.2, 4.2) than on actual devices. Because:

iPad ? xibName = @"MyViewController-iPad" : @"MyViewController";

works perfect on those simulators but fails on my iPhone 4 (4.1)

while writing this way:

xibName = (iPad) ? @"MyViewController-iPad" : @"MyViewController";

allows it to work on both the simulators and device.

Anyone can tell why? Is it a bug? Is the "2nd version" better and i should always write that way?

it's strange how compiler accepts both and simulators work with both but the device only accepts one... maybe a bug for apple to check out?

xfze
  • 765
  • 1
  • 9
  • 24

1 Answers1

10

These statements are not equivalent.

// iPad ? xibName = @"MyViewController-iPad" : @"MyViewController";
if ( iPad ) {
    xibName = @"MyViewController-iPad";
} else {
    @"MyViewController"; // Effectively a NOP
}

// xibName = (iPad) ? @"MyViewController-iPad" : @"MyViewController";
if ( iPad ) {
    xibName = @"MyViewController-iPad";
} else {
    xibName = @"MyViewController";
}

For !iPad ( like say, on an iPhone 4 ) with the first statement xibName would not get set at all, I am guessing you only ran an iPad simulator, not an iPhone.

Dre
  • 4,298
  • 30
  • 39
  • As i wrote i DID ran the following sims: iPad 3.2, iPad 4.2, iPhone 4.1, iPhone 4.2. And it loaded correctly the xib in each case. I understand that my initial code was a bit incorrect and i thank you for the explanation (it clears very well the "translation to if"). Anyway it's funny how the sims do evaluate "correctly" the code and the device doesn't – xfze Mar 05 '11 at 19:18