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
3
u/andyscorner May 17 '20
It means that in your AppDelegate class you have the method declared twice. Remove one of the declarations and you should be fine. You might also want to check that you don't have different implementations in your duplicate method definitions. In that case you might want to merge the method implementations.
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.
1
u/[deleted] May 21 '20
Give your methods better names. ObjC doesn’t have method overloading if that’s what you were going for.