admin管理员组文章数量:1405392
I would like to create a temporary BOOL property in a custom NSManagedObject class to track whether an async download of a remote image is underway so as not to start a second download while the first is underway. This value would not be stored in Core Data and is not included in xcmodel. It is supposed to be short term state variable to prevent recursive downloads.
In the past, I've often added properties to custom NSManagedObject class files with no problem. However, in this case, the managedobjects are being fetched with a FetchedResultsController into a tableview. Aalthough adding a BOOL to the class gets past the compiler it crashes at runtime.
When I look at the custom class in the debugger, it appears the BOOL property is not listed. Could it be that when you fetch managed objects using a fetchedResultsController, it ignores any properties that are not in the xcmodeldata file?
Here is the error message(abbreviated):
CoreData: error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. -[Feed awaitingResponse]: unrecognized selector sent to instance 0x6000021d8910 with userInfo (null)
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Feed awaitingResponse]: unrecognized selector sent to instance 0x6000021d8910'
Here is my code.
Feed.h
@property (nonatomic, assign) BOOL awaitingResponse;
Feed.m
@dynamic awaitingResponse;
- (void)awakeFromInsert {
self.awaitingResponse = NO;//Attempt to set a default value. Compiles okay.
}
The crash occurs, although the following compiles, when I try to access the property from another class as follows:
@implementation FeedViewController
- (void)configureCell:(FeedCell *)cell withFeed: (Feed *)aFeed {
BOOL awaitingResponse = aFeed.awaitingResponse;//CRASH OCCURS HERE
}
I would like to use this BOOL to condition remote fetches of data, however, I can't even try to access it without getting the crash at runtime.
How can I get and set values of this property?
I would like to create a temporary BOOL property in a custom NSManagedObject class to track whether an async download of a remote image is underway so as not to start a second download while the first is underway. This value would not be stored in Core Data and is not included in xcmodel. It is supposed to be short term state variable to prevent recursive downloads.
In the past, I've often added properties to custom NSManagedObject class files with no problem. However, in this case, the managedobjects are being fetched with a FetchedResultsController into a tableview. Aalthough adding a BOOL to the class gets past the compiler it crashes at runtime.
When I look at the custom class in the debugger, it appears the BOOL property is not listed. Could it be that when you fetch managed objects using a fetchedResultsController, it ignores any properties that are not in the xcmodeldata file?
Here is the error message(abbreviated):
CoreData: error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. -[Feed awaitingResponse]: unrecognized selector sent to instance 0x6000021d8910 with userInfo (null)
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Feed awaitingResponse]: unrecognized selector sent to instance 0x6000021d8910'
Here is my code.
Feed.h
@property (nonatomic, assign) BOOL awaitingResponse;
Feed.m
@dynamic awaitingResponse;
- (void)awakeFromInsert {
self.awaitingResponse = NO;//Attempt to set a default value. Compiles okay.
}
The crash occurs, although the following compiles, when I try to access the property from another class as follows:
@implementation FeedViewController
- (void)configureCell:(FeedCell *)cell withFeed: (Feed *)aFeed {
BOOL awaitingResponse = aFeed.awaitingResponse;//CRASH OCCURS HERE
}
I would like to use this BOOL to condition remote fetches of data, however, I can't even try to access it without getting the crash at runtime.
How can I get and set values of this property?
Share Improve this question edited Mar 22 at 16:12 user6631314 asked Mar 22 at 15:31 user6631314user6631314 1,9781 gold badge18 silver badges60 bronze badges 1 |1 Answer
Reset to default 0Using @dynamic means you are planning to add implementations of the getter/setter methods at runtime, the way CoreData usually does (via low-level runtime stuff like -resolveInstanceMethod). If you don't, they won't exist despite the declaration in the .h saying they do, so you will get an exception if you try to call them at runtime.
Simply remove the @dynamic line -- the default should cause the compiler to generate the normal getter/setter methods and I think it should work. @dynamic is for properties that CoreData knows how to manage at runtime.
本文标签:
版权声明:本文标题:core data - Access value of convenience property in custom NSManagedObject class in Objective-C causing crash - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744310023a2599982.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
dynamic
property? You can add property in model and set it default value and get generated by xcode h,m files. – Cy-4AH Commented Mar 24 at 15:50