Home > iPhone SDK > Core Data - Determining if a Managed Object is New
Core Data - Determining if a Managed Object is New
Posted on Wednesday, July 1, 2009 by android apps market for tablests
Sorry for the dearth of OpenGL ES posts. Things are quite hectic now with writing More iPhone Development, and I'm not even fully caught up from the week spent at WWDC. So, it may be a little while before I'm able to get another substantive post out like another OpenGL ES tutorial.
Anyone working with Core Data may appreciate this short category I wrote, with some help from Jim Dovey. Curiously enough, managed objects don't know if they are new or not. That is to say, whether they've been added to the context since the last load or save. I've found this to be a piece of information I've needed a lot, so wrapped up the check into a category.
NSManagedObject-isNew.h
NSManagedObject-isNew.m
Then you can just add these files to your project, #import the header file, and then you can ask any managed object if it's new by sending it an isNew message.
Anyone working with Core Data may appreciate this short category I wrote, with some help from Jim Dovey. Curiously enough, managed objects don't know if they are new or not. That is to say, whether they've been added to the context since the last load or save. I've found this to be a piece of information I've needed a lot, so wrapped up the check into a category.
NSManagedObject-isNew.h
//
// NSManagedObject-IsNew.h
#import <Foundation/Foundation.h>
@interface NSManagedObject(IsNew)
/*!
@method isNew
@abstract Returns YES if this managed object is new and has not yet been saved yet into the persistent store.
*/
-(BOOL)isNew;
@end
NSManagedObject-isNew.m
//
// NSManagedObject-IsNew.m
//
#import "NSManagedObject-IsNew.h"
@implementation NSManagedObject(IsNew)
-(BOOL)isNew
{
NSDictionary *vals = [self committedValuesForKeys:nil];
return [vals count] == 0;
}
@end
Then you can just add these files to your project, #import the header file, and then you can ask any managed object if it's new by sending it an isNew message.
Category Article Cocoa, Cocoa Touch, Core Data, iPhone SDK
Powered by Blogger.
Blog Archive
-
▼
2009
(496)
-
▼
July
(61)
- We're Listening
- We're Listening
- The Iterative Web App: Links Got Shorter and Smarter
- The Iterative Web App: Links Got Shorter and Smarter
- DP aka Dataran Pahlawan Malacca.
- The Most Reliable
- Google Latitude. Now for iPhone.
- Google Latitude. Now for iPhone.
- Interesting Contrast
- Waving the Red Flag
- Microsoft's Ads Redux
- Layers of fun in Google Maps for mobile 3.2
- Layers of fun in Google Maps for mobile 3.2
- August 14 Workshop Update
- To VBO or Not to VBO...
- Improved Blender Export
- Refactoring Nav from Chapter 9
- Voyager Class Mixmaster
- Fixed & Improved Blender Export Script
- How MJ Died..
- A Little Ego Boost for a Friday
- WWDC 2009 Videos Available for Purchase
- Beginning iPhone 3 Development is Available
- Gah! Up is Down! Right is Wrong! Make it Stop!
- First Post
- Search with My Location for iPhone 3.0. And All t...
- Search with My Location for iPhone 3.0. And All t...
- Browse a collection of experts' favorite places us...
- Browse a collection of experts' favorite places us...
- New Device Rules
- Updating Project Hint
- Google Voice for Android and BlackBerry
- Google Voice for Android and BlackBerry
- Detail Editor Update: To Many Relationships
- Generic Detail Editor Update
- August 14 Workshop
- A Category on NSDate
- unusual business ideas that work Gadget
- Core Data Default Dates in Data Model
- A Kick-Ass Objective-C Programmer is a Kick-Ass C ...
- TinyPlayground Gadget
- Google Product Search for mobile now available for...
- Google Product Search for mobile now available for...
- Travelzoo UK Deals
- In Search of a Better Way: Editable Detail Views
- The Perils of Helping Others
- Core Plot
- More on Teaching
- An IPhone App Setback
- Oh, Good, Here Comes the Justice Department
- Windows Mobile: World Domination is In Sight!
- Core Data Navigation-Based Application
- iPhone Simulator Application Creator
- Wireless Carriers the Great Train Robbers of this ...
- An Exercise in Blatant Bias
- Core Data - Inserting a New Managed Object
- Google Search results optimized for feature phones...
- Google Search results optimized for feature phones...
- What, Me Teach?
- Mint Apps Promo Day is Today!
- Core Data - Determining if a Managed Object is New
-
▼
July
(61)