Protocol versus Interface

I read quick documentation and worked on the playground. I have to admit that I have zero knowledge of Objective-C / iOS development (at least outside of Xamarin). In my opinion, the protocol seemed identical to the C # interface.

However, I noticed that when browsing the Internet, Objective-C has the concept of both a protocol ( source ) and an interface (although I'm not really sure what the difference is). Swift doesn't seem to have both - just protocols.

Can anyone explain, for a quick one, what is the difference / communication between the protocol and the C # interface?

Update: I understand that the answer may be functionally the same as the listed duplicates, but I think that, given that it asks for a different language, this question still has the right to itself. In the end, new developers may quickly not know Java (except for Javascript, I don’t have them). To believe that someone has knowledge of a completely different language system in order to get an answer to their question is not much, right ?? This meta discussion also discusses this issue.

+6
source share
1 answer

Objective-C protocols serve basically the same purpose as interfaces in Java / C #. Objective-C interface files are different. Like C, Objective-C has interface files that publicly declare class methods and properties, which are then implemented in the implementation file. For example, you might have a class interface file that looks something like this:

@interface -(void)myMethod; @end 

then in your implementation file you really implement the method:

 -(void)myMethod{ //code } 

Swift deletes individual interface and implementation files. Thus, it has only protocols.

+9
source

Source: https://habr.com/ru/post/970321/


All Articles