“No visible @interface for 'BlahDataController' declares the selector 'aMethod:'”

前端 未结 5 1185
無奈伤痛
無奈伤痛 2020-12-08 14:12

A simple example of my problem:

\"Within the BlahDataController.h\"

@interface BlahDataController : NSObject
-(NSString *)aMethod:(NSString *)theStri         


        
相关标签:
5条回答
  • 2020-12-08 14:25

    tl;dr - There's a duplicate file somewhere in the project! Go hunt it down and destroy it mercilessly!

    Ok, for all those in the future with this issue; this is what the problem was.

    I had made BlahDataController months ago. About a week ago, I restructured the folders of the project and moved BlahDataController from a folder called "Blah" to another folder called "Data".

    When I changed the code for BlahDataController within the "Data" folder, one of my classes could see the changed code, however, another class couldn't.

    What ended up being the issue was that when I moved BlahDataController, it actually created a copy of it. So I had a BlahDataController in the "Data" folder, and an older BlahDataController in the "Blah" folder. Even though the older BlahDataController was no longer attached to the project in the project manager (left side of xcode), the fact that the physical file still existed in the folder caused this issue.

    After deleting the duplicate older copy of BlahDataController, the issue was resolved.

    0 讨论(0)
  • 2020-12-08 14:36

    If someone stumbles upon a similar problem, in my case I did some refactoring using "Find & Replace" feature (ignoring case) and I obtained something like this:

    SomeClass* SomeClass = [[SomeClass alloc] init];
    [SomeClass instanceMethod];
    

    and it was saying: "No visible @interface for 'SomeClass' declares the method 'alloc'. So in my case the problem was I renamed the instance variable to upper case. The solution was:

    SomeClass* someClass = [[SomeClass alloc] init];
    [someClass instanceMethod];
    

    PS: I recommend using the "Refactor" feature in Xcode instead of "Find & Replace" if possible.

    0 讨论(0)
  • 2020-12-08 14:37

    Note: not the answer for this exact question, but I got here searching for the same compiler error.

    Make sure you know if you are calling the instance method or static method:

    @interface SomeClass

    +(void) SomeMethod;
    

    vs.

    -(void) SomeMethod;
    

    These are different.

    [SomeClass SomeMethod];
    

    vs.

    [[[SomeClass alloc] init] SomeMethod];
    
    0 讨论(0)
  • 2020-12-08 14:37

    Also note that this might happen (e.g. with the master/detail project template) if the

    "Other Linker Flags"
    

    value is set to

    -ObjC
    

    as required by some frameworks, e.g. RestKit (issue at RestKits github page: https://github.com/RestKit/RestKit/issues/1153)

    0 讨论(0)
  • 2020-12-08 14:46

    Yes I had the same problem. I had this working perfect in my Paid Target though when I changed to my Free Target I got this error.

    No visible @interface for 'GameOverScene' declares the selector mesageToDisplayOnLabel:

    • to fix this the spelling of my method call was different to the method I was calling.

      -(void)messageToDisplayOnLabel //I'm missing the s in "message" in my method call Doh!
      {
      //method code
      }

    • check the spelling of the method you are calling might help.

    0 讨论(0)
提交回复
热议问题