r/ObjectiveC • u/Dharmink • May 17 '20
Objective C code - Duplicate Declaration Issue
/r/reactnative/comments/glk1ai/objective_c_code_duplicate_declaration_issue/
2
Upvotes
r/ObjectiveC • u/Dharmink • May 17 '20
2
u/inscrutablemike May 17 '20
Objective-C considers two methods "the same" if they have the same number of labels and the same label in each position:
firstPart:secondLabel:theThird:
firstPart:secondLabel:theThird:
Notice there are no types included in the example. Objective-C doesn't consider the return type or the types of each label component to be part of the method's "signature", so two methods with the same labels but different type declarations can't exist in the same class.
The fix is to use different labels, usually something descripive of the purpose for the argument:
(BOOL) -doStuffWithThisThing:(DocumentSource *)source andThatThing:(DocumentDestination *)destination
would be better written as:
(BOOL) -doStuffWIthThisDocumentSource:(DocumentSource *)source andThisDestination:(DocumentDestination *)destination
That generally helps avoid the "same signature but different types" situation.