返回-application的类型:didFinishLaunchingWithOptions: [英] Return Type of -application:didFinishLaunchingWithOptions:

查看:807
本文介绍了返回-application的类型:didFinishLaunchingWithOptions:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在为iOS开发时,您应用的第一个入口点是 - [AppDelegate应用程序:didFinishLaunchingWithOptions:] 。此方法的返回类型是 BOOL 。默认情况下,此方法的返回类型为 YES 。这里是通过Xcode的自动生成的代码

When developing for iOS, the first entry point for your app is the -[AppDelegate application:didFinishLaunchingWithOptions:]. The return type of this method is a BOOL. By default, the return type of this method is YES. Here is the code automatically generated by Xcode.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

    return YES;
}

正如您所看到的,Xcode为您提供了返回声明,值。当我将return语句的值更改为 NO ,并且不更改任何其他内容时,没有任何反应。该应用程序不会退出或显示任何异常行为。这引出了一个问题,返回BOOL的方法的目的是什么,当返回的值无关紧要?如果返回的值无关紧要,为什么方法不返回void ?

注意:将回报更改为后,我的一些期望是

As you can see, Xcode puts in the return statement for you, with the value of YES. When I change the value of the return statement to NO, and don't change anything else, nothing happens. The app doesn't quit or show any unusual behavior. This begs the question, what is the purpose of the method returning a BOOL, when the returned value doesn't matter? If the value returned doesn't matter, why doesn't the method just return void?
Note: Some of my expectations after changing the return to NO were either


  • 申请未启动,因为它未收到许可(已退回)

  • 编译器都会生成警告,或者在运行时引发错误。

    为什么这些都不会发生?

  • Application doesn't launch because it doesn't receive "permission" (NO is returned)
  • Either compiler generates warning, or error is raised at runtime.
    Why is it the case that neither of these things happen?

推荐答案

如果 launchOptions 中有一个网址,则返回,然后操作系统将知道您由于某种原因无法打开提供的URL。

If there is a URL in launchOptions and you return NO, then the operating system will know that you cannot open the provided URL for some reason.

它不用于其他任何内容。由于 launchOptions 通常没有URL,因此返回的内容通常无关紧要。

It's not used for anything else. Since usually there is no URL in launchOptions it usually doesn't matter what you return.

所以只需返回。您可以在苹果文档的这里

So just return YES. You can read more in the Apple documentation here.

这篇关于返回-application的类型:didFinishLaunchingWithOptions:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆