2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-04-28 16:49:39 +02:00
It may seem cleaner to omit keywords from your method declarations, but this is one time you should err on the side of verbosity. Omitting keywords in a declaration necessarily means that they'll be omitted from calls too. What results is code that will be impenetrable to maintainers. That's why it's considered best practice to always use keywords. This applies both to Objective-C-style parameters without keywords, and to C-style parameter declarations, which are deprecated.
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,cpp]
2021-04-28 16:49:39 +02:00
----
@interface MyAction
- (void)sendAction:(int)anAction :(int)flag; // Noncompliant
- (void)seekAction:(int)anAction, int flag; // Noncompliant; hard on maintainers AND deprecated
@end
void test(MyAction* myAction) {
[myAction sendAction:1 :1];
[myAction sendAction:1 forAllCells:1]; // warning: 'MyAction' may not respond to 'sendAction:forAllCells:'
[myAction seekAction:1 :1];
}
----
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,cpp]
2021-04-28 16:49:39 +02:00
----
@interface MyAction
- (void)sendAction:(int)anAction forAllCells:(int)flag;
- (void)seekAction:(int)anAction forAllCells:(int)flag;
@end
void test(MyAction* myAction) {
[myAction sendAction:1 forAllCells:1];
[myAction seekAction:1 forAllCells:1];
}
----
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
== Resources
2021-04-28 16:49:39 +02:00
* https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingMethods.html[Coding Guidelines for Cocoa] - Naming Methods
2021-04-28 18:08:03 +02:00
2021-09-20 15:38:42 +02:00
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== Message
* Add a keyword before this argument.
* Update this C-style parameter to conform to Objective-C standards.
=== Highlighting
keyword-less arg
2021-09-20 15:38:42 +02:00
endif::env-github,rspecator-view[]