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

- (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.

https://stackoverflow.com/questions/5678360/

相关文章:

objective-c - 调用 -retainCount 被认为是有害的

c++ - UInt8 和 uint8_t 有什么区别

ios - scaledValueForValue : called on a font that

objective-c - 如何在 Objective-C 中命名常量?

ios - 在从 UIViewController 调用的非保留完成中引用 self 时,weakS

objective-c - 在子类中覆盖初始化

objective-c - CAEmitterLayer 在触摸事件中随机发射不需要的粒子

iphone - viewWillAppear,viewDidAppear 没有被调用,没有触发

ios - UIImagePickerController 相机 View 在 iOS 8 上奇怪地

objective-c - 使用 JSON (iOS) 的 Cocoa 错误 3840