如果属性名以新开头,则应用程序崩溃 [英] Application crashes if a property name starts with new

查看:296
本文介绍了如果属性名以新开头,则应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我使用coredata。其中一个实体具有名为 newTotal 的属性,在其相应的NSManagedObject类中,属性声明为

In my project I'm using coredata. One of the entity has an attribute named newTotal, in its corresponding NSManagedObject class the property declaration is like

@property (nonatomic, strong) NSString *newTotal;

如果我在NSObject子类中添加这样的属性,XCode会显示类似

If I add a property like this in an NSObject subclass the XCode will show an error like

error: property's synthesized getter follows Cocoa naming convention for returning 'owned' objects

但是在NSManaged对象子类中,它不会显示错误,但是访问属性时应用程序崩溃,类似 EXC_BAD_ACCESS

But in NSManaged object subclasses it's not showing the error but the application crashes when the property is accessed, something saying like EXC_BAD_ACCESS.

为什么XCode不会显示错误,但应用程序崩溃?这是XCode / clang / LLVM的错误吗?

Why XCode not showing error but application crashes?. Is this a bug with XCode/clang/LLVM ?

我知道它与synthesize有关的东西。 NSManagedObject子类不合成其中的属性,但是@dynamic指令只告诉编译器getter和setter方法不是由类本身实现,而是在其他地方(如超类或将在运行时提供)实现。但我没有清楚的想法这一点。

I know its something related to the synthesize. NSManagedObject sub classes not synthesizing the property in it, but the @dynamic directive just tells the compiler that the getter and setter methods are implemented not by the class itself but somewhere else (like the superclass or will be provided at runtime). But I have no clear Idea about this. Can anybody can give a clear idea about the problem?

推荐答案

我可以看到你在使用ARC。

I can see you are using ARC.

在ARC内存管理为你,但有几件事你可以/必须做自己。您不能将属性newXxxx命名为:

In ARC memory is managed for you, but there are few things you can/have to do yourself. You cannot name property "newXxxx" because:

https://developer.apple.com/library/mac/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html

您不能给访问者以新开头的名称。这反过来意味着你不能,例如,声明一个名称以new开头的属性,除非你指定一个不同的getter:

You cannot give an accessor a name that begins with new. This in turn means that you can’t, for example, declare a property whose name begins with new unless you specify a different getter:

//不工作:

@property NSString *newTitle;

// Works:

@property (getter=theNewTitle) NSString *newTitle;

这篇关于如果属性名以新开头,则应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆