Application crashes if the property name starts with a new one

In my project, I am using coredata. One of the objects has an attribute named newTotal , in the corresponding NSManagedObject class, the property declaration is similar to

@property (nonatomic, strong) NSString *newTotal;

If I add such a property to a subclass of NSObject, Xcode will show an error, for example

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

But in subclasses of NSManaged objects, it does not show an error, but the application crashes when accessing the resource, something says EXC_BAD_ACCESS .

Why does Xcode not show an error but the application crashes ?. Is this a bug with Xcode / clang / LLVM?

I know something related to synthesis. NSManagedObject routines do not synthesize a property in it, but the @dynamic directive simply tells the compiler that the getter and setter methods are not implemented by the class itself, but somewhere else (for example, a superclass or will be provided at run time). But I have no clear idea about this. Can someone give a clear idea of ​​the problem?

+4
source share
1 answer

I see that you are using ARC.

The ARC memory is managed for you, but there are a few things you can / should do yourself. You cannot name the property "newXxxx" because:

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

, . , , , , , , new, getter:

// :

@property NSString *newTitle;

//:

@property (getter=theNewTitle) NSString *newTitle;
+5

Source: https://habr.com/ru/post/1523293/


All Articles