gpt4 book ai didi

objective-c - 如何摆脱 objective c typedef 中的可空性警告?

转载 作者:搜寻专家 更新时间:2023-10-30 20:15:14 25 4
gpt4 key购买 nike

此代码在 XCode 中产生“指针缺少可空性类型说明符”警告,我猜不出如何消除该警告。

NS_ASSUME_NONNULL_BEGIN

@interface MyClass : NSObject

typedef id (^MyBlock)(id object);

@end

NS_ASSUME_NONNULL_END

以下不会消除警告:

typedef __nonnull id (^MyBlock)(__nonnull id object);
typedef nonnull id (^MyBlock)(nonnull id object);

如果有任何建议,我将不胜感激。

谢谢。

最佳答案

typedef types don’t usually have an inherent nullability—they can easily be either nullable or non-nullable depending on the context. Therefore, typedef types are not assumed to be nonnull, even within audited regions.[1]

下面的语法可以正常工作

typedef __nonnull id (^MyBlock)(__nonnull id object);

关于objective-c - 如何摆脱 objective c typedef 中的可空性警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34390503/

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