Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semicolon after the method name in Objective-C implementation file

- (void) designImageViewNow; {

//some code here

}

Is it correct to write semicolon ; just after the method name before body brackets in the implementation file objective-c.

Would this work?

As I am working on an iPhone app, I put the semicolon after the method name in one of my custom class by mistakenly. But there was no warning or any crash. In fact it is working fine.

like image 934
Rajender Kumar Avatar asked Apr 15 '11 14:04

Rajender Kumar


2 Answers

Yes, it is acceptable syntax to do this.

In fact, I always do this in my implementations, because it then is trivial to copy and paste a method definition from interface to implementation and vice versa without having to remember where you are. It helps that I use aligned brackets on separate lines, as well.

Wil Shipley 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.

like image 163
Brad Larson Avatar answered Nov 06 '22 04:11

Brad Larson


Grammatically it is OK to put a semicolon there. It serves no purpose, and it is discouraged to do that. Some compilers give warnings about this extra semicolon.

like image 21
Yuji Avatar answered Nov 06 '22 02:11

Yuji