gpt4 book ai didi

objective-c - 忽略 Objective-C 中的 "Property type is incompatible with type inherited from"警告

转载 作者:搜寻专家 更新时间:2023-10-30 19:49:22 26 4
gpt4 key购买 nike

在子类中,我将属性的类型重写为该属性的子类,其工作方式如下:

ClassA: NSObject
@property (nonatomic) NSValue *value;

ClassB : ClassA
@property (nonatomic) NSNumber *value;

但是,我发现如果 ClassA 没有 #import NSNumber 类,那么 ClassB 就会有以下形式的警告:Property type 'NSNumber *' is incompatible with type 'NSValue *' inherited from 'ClassA'

我不想在 ClassA 中有一堆不必要的导入。我怎样才能覆盖来自 Clang 的警告?我知道语法是:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-somethingGoesHere"
#pragma clang diagnostic pop

但我不知道我应该传递什么标志。有什么地方可以查找该警告要传递的标志吗?我引用了 Clang User manual并尝试使用 "-w" 标志禁用该行的所有警告,但这没有用。

最佳答案

您可以在 Xcode 构建日志事件中显示警告并找到 clang 标志。试试这个:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wincompatible-property-type"
...
#pragma clang diagnostic pop

关于objective-c - 忽略 Objective-C 中的 "Property type is incompatible with type inherited from"警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15126060/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com