Xcode 警告:“属性 ''及其超类 ''没有匹配的“原子”;属性”

发布于 2024-09-30 16:28:23 字数 940 浏览 5 评论 0原文

在编译多个子类现有 Cocoa 类的类时,我收到 Xcode 警告。例如,以下类

   @interface HMAttitude : CMAttitude
    {
        double pitch;
        double roll;
        double yaw;
    }

    @property (readwrite) double pitch;
    @property (readwrite) double roll;
    @property (readwrite) double yaw;

    @end

-

@implementation HMAttitude

@synthesize pitch, roll, yaw;

- (id) init
{
    return [super init];
}

@end

产生三个警告

警告:属性“yaw”及其超类“CMAttitude”没有匹配的“atomic”属性

警告:属性“pitch”及其超类“CMAttitude”没有匹配“atomic”属性

警告:属性“roll”及其超类“CMAttitude”没有匹配的“atomic”属性

为了创建能够像超类一样运行的 CMMotionManager 和 CLLocationManager 子类,需要所有相关子类从 csv 文件加载数据。我对它们进行子类化的唯一原因是获得访问(或覆盖)它们的只读属性。如果无法设置这些属性,我就无法返回与真实 CMMotionManager 和 CLLocationManager 类相同的对象。

目前,除了必须使用 #pragma 来忽略稍微让我烦恼的警告之外,一切正常。

有谁知道为什么会生成此警告?鉴于属性没有设置为非原子(原子是默认值),我完全没有任何线索。

为了使这些属性成为原子属性,我需要明确执行什么操作吗?

I'm getting an Xcode warning when compiling several class that subclass existing Cocoa classes. For example, the following class

   @interface HMAttitude : CMAttitude
    {
        double pitch;
        double roll;
        double yaw;
    }

    @property (readwrite) double pitch;
    @property (readwrite) double roll;
    @property (readwrite) double yaw;

    @end

-

@implementation HMAttitude

@synthesize pitch, roll, yaw;

- (id) init
{
    return [super init];
}

@end

yields three warnings

warning: property 'yaw' and its super class 'CMAttitude' don't have matching 'atomic' attribute

warning: property 'pitch' and its super class 'CMAttitude' don't have matching 'atomic' attribute

warning: property 'roll' and its super class 'CMAttitude' don't have matching 'atomic' attribute

All of the subclasses in question are required in order to create CMMotionManager and CLLocationManager subclasses capable of acting like the superclasses, only loading their data from a csv file. The only reason that I am subclassing them is to gain access (or override) their read-only properties. Without the ability to set these properties, I have no way of returning the same objects as the real CMMotionManager and CLLocationManager classes.

Currently everything works fine aside from having to use a #pragma to ignore the warning which slightly bothers me.

Does anyone know why this warning is being generated? Given the properties aren't being set to nonatomic (atomic is the default), I have no absolutely no clue.

Is there anything that I need to explicitly do in order for these properties to be atomic?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼眸 2024-10-07 16:28:23

如果您查看 CMAttitude 文档,您会看到它们实际上被声明为-原子。因此,您也应该将您的属性声明为非原子属性。

The error message is slightly confusing—if you look at the definition of those properties in the CMAttitude documentation, you'll see that they're actually declared as non-atomic. So, you should declare your properties as non-atomic as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文