@interface and @protocol explanation?

前端 未结 3 1091
名媛妹妹
名媛妹妹 2020-12-07 12:44

I would like to know what the @interface in objective C is? is it just where the programmer want to declare the variables, class name or method names...? I am not sure wheth

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-07 13:36

    probably good if you take a look at this + I thought it was great help to understand

    From the article:

    @interface

    C++

    Foo.h

    #ifndef __FOO_H__
    #define __FOO_H__
    class Foo
    {
    ...
    };
    

    Foo.cpp

    #include "Foo.h"
    ...
    

    Objective-C

    Foo.h

    @interface Foo : NSObject
    {
    ...
    }
    @end
    

    Foo.m

    #import "Foo.h"
    
    @implementation Foo
    ...
    @end
    

    @protocol

    C++

    struct MyInterface
    {
      void foo() = 0;
    }
    
    class A : MyInterface
    {
    public:
      void override foo() { ... }
    }
    

    Objective-C

    @protocol MyInterface
    -(void) foo;
    @end
    
    @interface Foo : NSObject 
    {
     -(void) foo {...}
    ...
    }
    @end
    

提交回复
热议问题