关于一个交叉引用Bug:“can not find interface declaration”

这是GCC编译器的一个Bug,在Xcode的任何版本都会报这个错误。

你有一个类A:

#import <Foundation/Foundation.h>

#import "B.h"

@interface A : NSObject

@end

 

#import "A.h"

@implementation A

@end

还有一个类B:

#import <Foundation/Foundation.h>

#import "A.h"

@interface B : NSObject

@end

#import "B.h"

@implementation B

@end

然后你决定从A继承一个类,子类C:

#import "A.h"

@interface C : A

@end

 

#import "C.h"

@implementation C

@end

一切,OK,编译通过。然后你决定让B也继承A:

#import <Foundation/Foundation.h>

#import "A.h"

@interface B : A

@end

这时候问题来了,编译器告诉你“can not find interface of declaration for ‘A’,superclass of ‘B’”。

怎么可能?B中明明import了A.h,而且通过command键+鼠标左键,也可以从B中找到A的接口声明。你尝试了各种方法,就是找不到问题出在哪里。而且C同样是A的子类,C和B除了类名外,代码没有任何不同。难道Cocoa限制了一个类的子类数量?一个子类可以继承,第2个就不行?

不用大惊失色。问题在于A中import了B.h,而B又引用了A,这就构成了交叉引用。不过编译器却给出了一个让人混淆不清的提示“找不到父类接口”。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
TS7016: Could not find a declaration file for module 'jest-matchers'. 'D:/Projects/Vue/Vue3/liantong/liantong_project/node_modules/_jest-matchers@18.1.0@jest-matchers/build/index.js' implicitly has an 'any' type. Try `npm i --save-dev @types/jest-matche`是一个 TypeScript 的错误提示。它告诉你在模块 'jest-matchers' 中找不到声明文件。这意味着编译器无法确定该模块的类型,因此将其标记为 'any' 类型。为了解决这个问题,你可以尝试运行命令 `npm i --save-dev @types/jest-matche` 来安装 '@types/jest-matche' 的声明文件,如果存在的话。这样编译器就能正确地推断出模块的类型。\[1\] 类似地,对于错误信息 TS7016: Could not find a declaration file for module 'mock-service-plugin'. 'app-ts/node_modules/mock-service-plugin/src/index.js' implicitly has an 'any' type. Try `npm i --save-dev @types/mock-service-plugin` if it exists or add a new declaration (.d.ts) file containing `declare module 'mock-service-plugin';`,你可以尝试运行命令 `npm i --save-dev @types/mock-service-plugin` 来安装 '@types/mock-service-plugin' 的声明文件,如果存在的话。或者你可以创建一个新的声明文件(.d.ts),并在其中添加 `declare module 'mock-service-plugin';` 的声明,以解决这个问题。\[2\] 对于错误提示 TS7016: Could not find a declaration file for module "./mock/IdeatUserHomeMock",它告诉你在模块 "./mock/IdeatUserHomeMock" 中找不到声明文件。编译器无法确定该模块的类型,因此将其标记为 'any' 类型。为了解决这个问题,你可以尝试创建一个新的声明文件(.d.ts),并在其中添加 `declare module './mock/IdeatUserHomeMock';` 的声明,以帮助编译器正确地推断出模块的类型。\[3\] #### 引用[.reference_title] - *1* [TS7016: Could not find a declaration file for module](https://blog.csdn.net/TO_Web/article/details/128015339)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [error TS7016: Could not find a declaration file for module ‘*‘.](https://blog.csdn.net/bianliuzhu/article/details/128685412)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [TS7016: Could not find a declaration file for module './mock/IdeatUserHomeMock'. '/Users/yangtianrui...](https://blog.csdn.net/weixin_42611177/article/details/129586645)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值