Your problem is most likely occurring because you're swizzling a method allocCustom
on UIAlertView
with the method alloc
, which is a method on NSObject
. From what I have found, you can successfully swizzle NSObject
's alloc method, but it doesn't appear you can do this from a subclass. You can see evidence that this is the case by adding the following to your UIAlertView
category:
+ (id)alloc
{
return [super alloc];
}
By doing that, it will now work correctly. But since alloc
is a method on NSObject
and clearly not being overridden by UIAlertView
anyway, you could just remove your method swizzling, and add your code to your overridden alloc
method:
+ (id)alloc
{
NSLog(@"Custom!");
return [super alloc];
}
Now this might be a little dangerous to do in case Apple at a future time changed their implementation and for some reason were overriding alloc
in UIAlertView
. In that case, I think your implementation would override theirs, although I think the exact behavior is technically undefined.