gpt4 book ai didi

iphone - Objective-C 实现文件中方法名后的分号

转载 作者:IT老高 更新时间:2023-10-28 11:46:51 27 4
gpt4 key购买 nike

- (void) designImageViewNow; {

//some code here

}

在实现文件objective-c中,在方法名后的方括号前,直接写分号;对吗?

这行得通吗?

在开发 iPhone 应用程序时,我错误地将分号放在了我的一个自定义类中的方法名称之后。但是没有警告或任何崩溃。事实上它工作得很好。

最佳答案

是的,这样做是可以接受的语法。

事实上,我总是在我的实现中这样做,因为这样就可以轻松地将方法定义从接口(interface)复制并粘贴到实现,反之亦然,而无需记住你在哪里。这也有助于我在单独的行上使用对齐的括号。

威尔·希普利 agrees with me on this :

End the definition lines on your method implementations with a semicolon, so you can copy-n-paste them to or from your header (or the "Private" category at the top of your file) as needed when they change. Semicolons are required in the "interface" section, but don't hurt anything in the "implementation" section.

关于iphone - Objective-C 实现文件中方法名后的分号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5678360/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com