ios ARC 语义问题:Class 没有可见的 @interface 声明选择器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16431902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ARC Semantic Issue: No visible @interface for Class declares the selector
提问by AJ112
Pretty basic stuff but i am unable to troubleshoot where the problem is. In my project, i have a class named "TheFeedStore" with following two methods:
非常基本的东西,但我无法解决问题所在。在我的项目中,我有一个名为“TheFeedStore”的类,它具有以下两种方法:
- (BOOL)hasItemBeenRead:(RSSItem *)item
{
............
}
- (void)markItemAsRead:(RSSItem *)item
{
.........
}
I am using the following class method so other classes can access these methods using it:
我正在使用以下类方法,以便其他类可以使用它访问这些方法:
+ (TheFeedStore *) sharedStore
{
static TheFeedStore *feedStore = nil;
if (!feedStore) {
feedStore = [[TheFeedStore alloc] init];
}
return feedStore;
}
In one of my another class, i can easily access the above methods by writing
在我的另一堂课中,我可以通过编写轻松访问上述方法
if ([[TheFeedStore sharedStore] hasItemBeenRead:item])
or
或者
[[TheFeedStore sharedStore] markItemAsRead:entry];
But in another class if i try to access these methods in a similar manner, i get the error "No visible @interface for 'TheFeedStore' declares the selector 'hasItemBeenRead:"
但是在另一个类中,如果我尝试以类似的方式访问这些方法,则会收到错误消息“‘TheFeedStore’没有可见的@interface 声明了选择器‘hasItemBeenRead:”
1) I have imported TheFeedStore.h file in the classes from i am accessing these methods of TheFeedStore class.
2) I have checked like 10 times and there is no typo.
3) The methods i am accessing are also declared in the header file of TheFeedStore.h
1) 我在类中导入了 TheFeedStore.h 文件,我正在访问 TheFeedStore 类的这些方法。
2)我已经检查了 10 次,没有错字。
3)我访问的方法也在TheFeedStore.h的头文件中声明
UPDATE:Just to check, i have declared another test method in TheFeedStore.h, same result, one class can access the newly created method while rest of the three classes cannot.
更新:只是为了检查,我在 TheFeedStore.h 中声明了另一个测试方法,结果相同,一个类可以访问新创建的方法,而其余三个类则不能。
UPDATE:I have tried creating more methods in the TheFeedStore.h just for troubleshooting this issue. The new methods are also not accessible from the other classes. But if the return type of these new methods is (RSSChannel*) which is another model class in my project, than they become accessible. If their return type is other than some class like (void) and (BOOL) then they are not accessible. Here is my TheFeedStore.h https://gist.github.com/jessicamoore112/5558473
更新:我已经尝试在 TheFeedStore.h 中创建更多方法来解决这个问题。其他类也无法访问新方法。但是,如果这些新方法的返回类型是 (RSSChannel*),这是我项目中的另一个模型类,那么它们将变得可访问。如果它们的返回类型不是像 (void) 和 (BOOL) 这样的类,那么它们是不可访问的。这是我的 TheFeedStore.h https://gist.github.com/jessicamoore112/5558473
回答by Jessica
You have said that you are using @class instead of #import in your header files, the methods that you are trying to access are declared in the header files and there are no typos of any kind.
您已经说过您在头文件中使用 @class 而不是 #import,您尝试访问的方法在头文件中声明,并且没有任何类型的拼写错误。
In such cases, usually no body points this issue but i am going to do it anyway because i have faced such issues many times. You have probably created many copies of your project to work on each functionality and also keeping a working project.
在这种情况下,通常没有机构指出这个问题,但无论如何我都会这样做,因为我已经多次遇到过这样的问题。您可能已经创建了许多项目副本来处理每个功能并保留一个工作项目。
When you do this, sometimes Xcode is still using the older copies of few files. That means it is still using the older copy of the TheFeedStore.h when the methods you are trying to access were not declared by you.
执行此操作时,有时 Xcode 仍在使用少数文件的旧副本。这意味着当您尝试访问的方法不是由您声明时,它仍在使用 TheFeedStore.h 的旧副本。
How to solve this problem is very simple. Go to the file from which you are trying to access the methods and the files in which these methods are declared.
如何解决这个问题很简单。转到您尝试访问方法的文件以及声明这些方法的文件。
In the Utilities section on the right hand side, check the location and full path under "Identity and Type" area.
在右侧的实用程序部分,检查“身份和类型”区域下的位置和完整路径。
First check the names of the project, if it is different from the project name that you are working on, that means Xcode is still pulling the old copies of the files from the previous revision of your project. See the blue arrows where the project name is 13SampleMoreRequests in my case.
首先检查项目的名称,如果它与您正在处理的项目名称不同,则表示 Xcode 仍在从项目的先前版本中提取文件的旧副本。在我的情况下,请参阅项目名称为 13SampleMoreRequests 的蓝色箭头。
If this name is same as your project name, then my answer does not solve your problem. If its different, you should use the new copies of the file by browsing the new location using the sign that is pointed out by red arrow.
如果此名称与您的项目名称相同,那么我的回答并不能解决您的问题。如果不同,您应该通过使用红色箭头指出的标志浏览新位置来使用文件的新副本。
Once you browse and use the new files, your problem will be solved and you will be able to access the methods. If you still can't, copy these files, delete from the project and then add them again and you won't face this problem.
浏览并使用新文件后,您的问题将得到解决,您将能够访问这些方法。如果还是不行,复制这些文件,从项目中删除,然后重新添加,你就不会遇到这个问题了。
Hope this helps!
希望这可以帮助!
回答by Sulthan
Cyclical imports, e.g. A.h
imports B.h
while also B.h
imports A.h
is the most common problem.
周期性进口,例如A.h
进口的B.h
同时也B.h
进口A.h
是最常见的问题。
In C, cyclical imports won't work and one of the imports will be silently ignored. Make sure you are not having a cyclical import. If you do, solve it (e.g. using forward declarations).
在 C 中,循环导入不起作用,其中一个导入将被默默忽略。确保您没有循环导入。如果你这样做,解决它(例如使用前向声明)。
Import problems can be also easily inspected if you generate the preprocessed output (you can find it in one of the Xcode menus).
如果您生成预处理的输出(您可以在其中一个 Xcode 菜单中找到它),也可以轻松检查导入问题。
回答by titicaca
That might sound silly, but I have similar cases once in a while and sometimes just simple quitting and starting xcode helps, it tends to stuck sometimes. Also, sometimes cleaning the project helps. 'Cause I have very similar to yours singleton code and it works fine.
这听起来可能很傻,但我偶尔也会遇到类似的情况,有时只是简单的退出和启动 xcode 有帮助,有时它往往会卡住。此外,有时清理项目会有所帮助。因为我有与你的单例代码非常相似的代码,它运行良好。
回答by webWizard
Guys I had encountered the exact same issues. After some searching on SO and the search engine I was able to solve it.
伙计们,我遇到了完全相同的问题。在对 SO 和搜索引擎进行了一些搜索之后,我能够解决它。
In my Case I have four files:
在我的情况下,我有四个文件:
- RadioStation.h
- RadioStation.m
- ViewController.h
- ViewController.m
- 电台.h
- 电台.m
- 视图控制器.h
- 视图控制器.m
My mistake was to place all my methods in RadioStation.m and only put my variables on radioStation.h So when I import radioSation.h on my ViewController.m and try to define methods for button-click on my app that's where the problems started. I got the error/warnings "ARC Semantic Issue: No visible @interface for Class declares the selector" every time I built or ran the app simulator.
我的错误是将我所有的方法放在 RadioStation.m 中,只将我的变量放在 radioStation.h 因此,当我在 ViewController.m 上导入 radioSation.h 并尝试定义按钮单击我的应用程序的方法时,问题开始了. 每次我构建或运行应用程序模拟器时,我都会收到错误/警告“ARC 语义问题:类没有可见的 @interface 声明选择器”。
My Solution was to go back to RadioStation.h file and just declare all my methods there. Since they were already defined on RadioStation.m I was good to go.
我的解决方案是回到 RadioStation.h 文件并在那里声明我的所有方法。因为它们已经在 RadioStation.m 上定义了,所以我很高兴。
So make sure you have properly declared your methods on the file that is going to be imported on your viewControllers. Hope that helps.
因此,请确保您已在将要导入 viewController 的文件上正确声明了您的方法。希望有帮助。
回答by Dirk
In my case I had some very strange path entries in
就我而言,我有一些非常奇怪的路径条目
- Framework Search Paths
- Library Search Path
- 框架搜索路径
- 图书馆检索路径
(Targets -> YOUR_APP_NAME -> Build Settings in "Search Paths" section)
(目标 -> YOUR_APP_NAME ->“搜索路径”部分中的构建设置)
I removed them and the error messages are gone.
我删除了它们,错误消息消失了。