• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Creating an NSInvocation from an NSMethodSignature
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating an NSInvocation from an NSMethodSignature


  • Subject: Re: Creating an NSInvocation from an NSMethodSignature
  • From: Marcel Weiher <email@hidden>
  • Date: Wed, 13 May 2009 12:30:56 -0700


On May 13, 2009, at 11:27 , Mike Mangino wrote:


I'm noticing something related that is causing my problems. I have mocking working for custom types. When I try to change the class of a string, however, I get a crash.


-(void) testImplementationOnString {
NSString *s = [NSString stringWithString:@"a test string"];
Class subclass = objc_allocateClassPair([s class], "MyStringMock", 0);
objc_registerClassPair(subclass);
//object_setClass(s, subclass);


}

If you uncomment the last line this crashes. Is that to be expected? I'm assuming it happens for toll free bridged types. Is that true? I've tried with NSString and NSArray and both cause a crash.

I think your suspicion is correct. What's the crash? Infinite recursion? The CF* functions check wether an object is exactly of the class that they are expecting, for example NSCFArray. If that's not the case, they will send a message instead. For a NSCFArray subclass, this will try to call the corresponding CF* function.


So I don't think you'll have much joy in trying to subclass any of the toll-free bridged classes. I guess Apple didn't include headers for the NSCF* classes for a reason...

I've got a workaround in place, but I'd love to be able perform the same mocking on these types. My code is available at http://github.com/mmangino/OCMock/tree/master

Marcel


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Creating an NSInvocation from an NSMethodSignature (From: Mike Mangino <email@hidden>)
 >Re: Creating an NSInvocation from an NSMethodSignature (From: Michael Ash <email@hidden>)
 >Re: Creating an NSInvocation from an NSMethodSignature (From: Mike Mangino <email@hidden>)
 >Re: Creating an NSInvocation from an NSMethodSignature (From: Michael Ash <email@hidden>)
 >Re: Creating an NSInvocation from an NSMethodSignature (From: Greg Parker <email@hidden>)
 >Re: Creating an NSInvocation from an NSMethodSignature (From: Mike Mangino <email@hidden>)

  • Prev by Date: Re: Questions about the xib file downgrade from Leopard to Tiger
  • Next by Date: Getting "Unknown class 'someClassName' in nib file" message
  • Previous by thread: Re: Creating an NSInvocation from an NSMethodSignature
  • Next by thread: Drawing 1 pixel line with zoom change
  • Index(es):
    • Date
    • Thread