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

标签 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.

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

相关文章:

ios - UINavigationBar 奇怪的标准高度

iphone - iOS 提高 PDF 渲染速度

iphone - 我有一个选项卡式 View ,如何触发该 View 来运行一些由选项卡式 View 激活的代码?

objective-c - objective-c 中的科学记数法(与基数 e 计算混淆)

ios - 如何检测 UITableView 中的最后一个可见单元格

ios - 我在 Controller 内调用 startDeviceMotionUpdatesToQueue 时得到 OSSpinLockLock

ios - 如何根据 iDevice 精确测量 Swift 节点的大小和位置

ios - 自定义UITableViewCell与UIImageView不显示图像

ios - 使用带有 GUI 用户请求的 iOS 应用程序连接到 WiFi,而不是以编程方式

ios - 减少警报 View 编码