开发者

Get access function in main.m [iPhone]

开发者 https://www.devze.com 2023-02-04 02:40 出处:网络
I\'m doing Universal Application and it has isPad() method inside of main.m class. I want to use this method inside of both AppDelegates (iPad, iPhone).

I'm doing Universal Application and it has isPad() method inside of main.m class. I want to use this method inside of both AppDelegates (iPad, iPhone).

Yes, it is currently accessible in a AppDelegates

**From AppDelegate

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
    if (isPad()) // isPad() method locates main.m and is accessible through delegate.
                 // but I gets warning message 'Implicit declaration of function isPad()
    {

    }
}

From main.m

BOOL isPad();
int main(int argc, char *argv[]) 
{ //detecting iPad and iPhone }
BOOL isPad()
{
   // method that detects the device.
}

Why Am I getting warning message 'Implicit declaration of function isPad()? Do I need to #include main.m inside of AppDelegate.m ? then how to ? I want to be use this method in any ot开发者_JS百科her classes.

[[UIApplication sharedApplication].delegate isPad()];

Yes, I made mistake!! I have used two delegate one for pad, and other for phone. It could be done in just using one delegate.

Sorry everyone!


Why have you put your isPad() method in main.m? Why can't you put that method in your shared app delegate, and that way all classes inside your app can access it? I would recommend simply creating your isPad() method inside of your shared app delegate and avoiding putting it in main.m all together.


  1. You are trying to call isPad() function on Objective C object.
  2. You defined your isPad() function inside main(), what's that?


The warning message you receive in the AppDelegate code is because there is no function prototype for isPad. You can get rid of the warning by putting BOOL isPad(); in your AppDelegate implementation file.

I strongly recommend you move this logic out of the main file.

0

精彩评论

暂无评论...
验证码 换一张
取 消