iOS - use of undeclared identifier

本文介绍了在iOS开发过程中遇到的头文件包含错误及其解决办法。主要原因是未正确包含所需的头文件,例如在使用UIAlertView时应包含/UIKit/UIKit.h而不是/UIKit/UIView.h。文章还提供了.pch文件中正确包含头文件的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

出现此类错误的主要原因为:

1.头文件包含出错。没要包含该类的头文件。在导入官方文档的时候。可能包含的不是总得头文件如

#import <UIKit/UIView.h>时 UIAlertView就不能使用正确做发是


#import <UIKit/UIKit.h>此时 UIKit下得所有头文件都被包含进去

通常情况下 此类文件在.pch文件下包含。如:
#ifndef ______MeiShi_pch
#define ______MeiShi_pch


#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "Define.h"

#endif

运行为14:42: error: use of undeclared type 'SystemImage' static func loadImage(named: String) -> SystemImage? { ^~~~~~~~~~~ 28:24: error: 'URLSession' is unavailable: This type has moved to the FoundationNetworking module. Import that module to use it. private let session = URLSession.shared ^~~~~~~~~~ Foundation.URLSession:2:18: note: 'URLSession' has been explicitly marked unavailable here public typealias URLSession = AnyObject ^ 50:22: error: use of unresolved identifier 'SystemLabel' private let label = SystemLabel() ^~~~~~~~~~~ 51:26: error: use of unresolved identifier 'SystemImageView' private let imageView = SystemImageView() ^~~~~~~~~~~~~~~ 52:23: error: use of unresolved identifier 'SystemButton' private let button = SystemButton() ^~~~~~~~~~~~ 54:11: error: initializer does not override a designated initializer from its superclass override init(frame: CGRect) { ~~~~~~~~ ^ 49:21: error: use of undeclared type 'SystemView' class PlatformView: SystemView { ^~~~~~~~~~ 55:3: error: 'super' members cannot be referenced in a root class super.init(frame: frame) ^ 60:3: error: 'super' members cannot be referenced in a root class super.init(coder: coder) ^ 67:21: error: use of unresolved identifier 'SystemColor' label.textColor = SystemColor.label ^~~~~~~~~~~ 68:3: error: use of unresolved identifier 'addSubview' addSubview(label) ^~~~~~~~~~ 73:3: error: use of unresolved identifier 'addSubview' addSubview(imageView) ^~~~~~~~~~ 83:3: error: use of unresolved identifier 'addSubview' addSubview(button) ^~~~~~~~~~ 90:3: error: use of unresolved identifier 'NSLayoutConstraint' NSLayoutConstraint.activate([ ^~~~~~~~~~~~~~~~~~ 91:48: error: use of unresolved identifier 'centerXAnchor' imageView.centerXAnchor.constraint(equalTo: centerXAnchor), ^~~~~~~~~~~~~ 92:44: error: use of unresolved identifier 'topAnchor' imageView.topAnchor.constraint(equalTo: topAnchor, constant: 20), ^~~~~~~~~ 97:44: error: use of unresolved identifier 'centerXAnchor' label.centerXAnchor.constraint(equalTo: centerXAnchor), ^~~~~~~~~~~~~ 100:45: error: use of unresolved identifier 'centerXAnchor' button.centerXAnchor.constraint(equalTo: centerXAnchor), ^~~~~~~~~~~~~
最新发布
07-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值