简体   繁体   English

XCode骨架项目覆盖

[英]XCode skeleton projects overriding

I'm pretty new to Objective-C, so I am not entirely sure of the terms I should be searching for. 我对Objective-C很新,所以我不完全确定我应该搜索的术语。 Apologies if you've seen this question before. 如果您之前看过这个问题,请道歉。

I have noticed that in the skeleton projects that XCode produces contain overrides like so: 我注意到在XCode生成的骨架项目中包含如下的覆盖:

- (void)viewDidLoad
{
    [super viewDidLoad];
}

I am not sure why this is part of the code that is generated. 我不确定为什么这是生成的代码的一部分。 I am confident that I could omit this method and not affect the application because it simply calls the method on the parent class. 我相信我可以省略这个方法而不会影响应用程序,因为它只是调用父类的方法。 Is this method stub just here to show the developer that they can override this commonly overridden method, or is this something in Objective-C that I have not yet come across? 这个方法存根就在这里向开发人员展示他们可以覆盖这个通常被覆盖的方法,或者这是Objective-C中的一些我还没有遇到过的东西?

It's a method that you'll often want to override, so it's included in the template as a convenience. 这是一种您经常想要覆盖的方法,因此为方便起见,它包含在模板中。 If you don't add any code of your own to it, you could as well remove it altogether because only calling super is the same as leaving it out. 如果你没有添加任何你自己的代码,你也可以完全删除它,因为只有调用super才能将它删除。

I suspect it's also included to remind you that you have to call super if you override it. 我怀疑它也包含在内,提醒你如果覆盖它就必须调用super。

Yes, if you have nothing to add to this method it could be left out. 是的,如果你没有任何东西可以添加到这个方法,它可能会被遗漏。 It is there to provide you a template where you can add your code for things you want done in viewDidLoad. 它是为您提供一个模板,您可以在其中添加您想要在viewDidLoad中完成的事情的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM