2

So I have been playing with GHUnit today, and have some nice tests which run just fine in the similator in XCode4. When I run them on the iPhone itself I get the following error:

'Unable to instantiate the UIApplication delegate instance.
No class named GHUnitIPhoneAppDelegate is loaded.'

Before you ask, yes I have the linker options -ObjC and -all_load set, and as I said, it works fine in the simulator, so why not the iPhone itself?

Puzzled!

iandotkelly
  • 9,024
  • 8
  • 48
  • 67

3 Answers3

3

I am not sure to have the real reason of this problem but I did find a workaround.

For a reason I am still not quite sure to understand replacing:

int retVal = UIApplicationMain(argc, argv, nil, @"GHUnitIPhoneAppDelegate");

by

int retVal = UIApplicationMain(argc, argv, nil, @"GHUnitIOSAppDelegate");

in the main file will fix the problem.

The class GHUnitIPhoneAppDelegate inherits from GHUnitIOSAppDelegate but it is not included in the final binary (I ran a nm -a GHUnitIPhoneAppDelegate|grep IPhoneAppwith no result).

A wild guess is that since the class only inherits from it (no additional methods or attributes) and because nowhere in the framework this class is instantiated (only mentioned through a string), the compiler, to save space, removes it from the binary information in iOS mode.

Hope this helps, at least that worked for me.

apouche
  • 9,703
  • 6
  • 40
  • 45
1

Just to clarify, GHUnitIOS-0.4.32 uploaded on 8/11/2011 to https://github.com/gabriel/gh-unit/downloads throws

NSInternalInconsistencyException', reason: 'Unable to instantiate the UIApplication delegate instance. No class named GHUnitIPhoneAppDelegate is loaded.'

if int main(int argc, char *argv[]) contains:

int retVal = UIApplicationMain(argc, argv, nil, @"GHUnitIPhoneAppDelegate");

It works for:

int retVal = UIApplicationMain(argc, argv, nil, @"GHUnitIOSAppDelegate");

As GHUnitIOSAppDelegate is missing from that armv6 & armv7 libs. Notice GHUnitIPhoneAppDelegate is in the simulator lib ...

GHUnitIOS.framework$ nm -a -arch i386 GHUnitIOS | grep GHUnitIPhoneAppDelegate
nm: no name list
GHUnitIOS(GHUnitIPhoneAppDelegate.o):
00000084 S _OBJC_CLASS_$_GHUnitIPhoneAppDelegate
00000070 S _OBJC_METACLASS_$_GHUnitIPhoneAppDelegate
00000048 s l_OBJC_CLASS_RO_$_GHUnitIPhoneAppDelegate
00000020 s l_OBJC_METACLASS_RO_$_GHUnitIPhoneAppDelegate
GHUnitIOS.framework$

But not in either of the two devices libs ...

GHUnitIOS.framework$ nm -a -arch armv6 GHUnitIOS | grep GHUnitIPhoneAppDelegate
nm: no name list
GHUnitIOS.framework$

GHUnitIOS.framework$ nm -a -arch armv7 GHUnitIOS | grep GHUnitIPhoneAppDelegate
nm: no name list
GHUnitIOS.framework$
mmorris
  • 4,006
  • 3
  • 27
  • 29
  • yep as mentioned in my response, this is probably compiler optimization since `GHUnitIPhoneAppDelegate` is never instantiated nor derived from. I'm guessing the compiler does more optimization when the final architecture is armv6/7, but I'd be curious to know the truth of it. – apouche Sep 07 '11 at 16:24
  • Yeah I would have posted a comment, but I do not have the power to do so yet. ;) Just wanted to clarify previous comments which made it seem like GHUnitIOS 0.4.32 would work with `GHUnitIPhoneAppDelegate` and it does not. – mmorris Sep 07 '11 at 17:04
0

I'll leave @apouche's answer as the accepted one, as this answered my problem and helped me out.

However had a message from gabriel, the developer of GHUnit - saying that this is a bug and that he's made a new release (0.4.32) which fixes this issue.

iandotkelly
  • 9,024
  • 8
  • 48
  • 67