Objective-C error "No visible @interface for 'XYZPerson' declares the selector 'saySomething'

前端 未结 3 1524
半阙折子戏
半阙折子戏 2021-01-16 13:36

I am really new to Objective-C and when I was practicing the book exercises, I really am stuck here. Please help me solve this and I have been thinking what could cause thi

3条回答
  •  伪装坚强ぢ
    2021-01-16 14:21

    It looks like you are testing inheritance so I will assume that XYZShout is supposed to be derived from XYZPerson. If so follow the suggestion from @JFS and make sure it does actually derive:

    XYZShout.h:

    #import 
    #import "XYZPerson.h"
    
    @interface XYZShout : XYZPerson
    
    - (void)saySomething:(NSString *)greet;
    
    @end
    

    And also correct the definition of saySomething in XYZPerson (you missed off the parameter):

    XYZPerson.h:

    #import 
    @interface XYZPerson : NSObject
    
    @property NSString *firstName;
    @property NSString *secondName;
    @property NSDate *dob;
    
    - (void)saySomething:(NSString *)greet;
    //                   ^^^^^^^^^^^^^^^^^
    - (void)sayHello;
    
    @end
    

提交回复
热议问题