tags:

views:

36

answers:

2

My iPad universal app has a method I implemented from here:

http://stackoverflow.com/questions/2862140/best-way-to-programmatically-detect-ipad-iphone-hardware

-(BOOL)isPad
{
  BOOL isPad;
  NSRange range = [[[UIDevice currentDevice] model] rangeOfString:@"iPad"];
  if(range.location==NSNotFound) isPad=NO;
  else isPad=YES;
  return isPad;
}

When I write my code like this:

if( [[[UIApplication sharedApplication] delegate] isPad] ) // do something

I get the warning:

'-isPad' not found in protocol

However, it's declared in my app delegate class:

-(BOOL)isPad;

And in the implementation (above).

Any ideas why this is?

Thanks in advance.

A: 

The compiler expects to find isPad declared in the uiapplicationdelegate protocol. Try making it an instance method of uiapplication instead.

ennuikiller
I made a reference variable and used that to call the method and it removed the warning. Thanks
just_another_coder
It would be simpler to call it the way I did it in the question, creating a ref variable every time is a pain.
just_another_coder
A: 

-delegate returns an id<UIApplicationDelegate>. Even if your app delegate supports -isPad, the UIApplicationDelegate does not, which is the warning is about.

You need to cast the return value to your class to eliminate the warning.

YourAppDelClass* appDel = [UIApplication sharedApplication].delegate;
if ([appDel isPad]) {
   ...
KennyTM
Yes, that's how I solved it, by creating a ref variable. Thanks for the help
just_another_coder
Would I be able to cast it in a define statement in an h file?
just_another_coder
Yes - #define kIsPad [(MyAppDelegate*)[[UIApplication sharedApplication] delegate] isPad]
just_another_coder