Following this [post][1]
, I am trying to parse out the numerical portion of the ObjectID in a ManagedObject where an auto increment apparently resides that is not ordinarily exposed through core data api. However, I always get 0 as a response.
Has anyone else done this or can anyone see why this is not working? Thanks in advance for any suggestions.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Item" inManagedObjectContext:self.managedObjectContext];
Items *newItem = [[Items alloc]initWithEntity:entity insertIntoManagedObjectContext:self.managedObjectContext];
NSURL *url = [[newItem objectID] URIRepresentation];
//get full url
NSString *url_string = [url absoluteString];
//split with a /
NSArray *parts = [url_string componentsSeparatedByString:@"/"];
NSString *last_segment=[parts objectAtIndex:[parts count]-1];
//p#
NSString *number_part = [last_segment stringByReplacingOccurrencesOfString:@"p" withString:@""];
NSUInteger auto_id = [number_part integerValue];
number_part =nil;
last_segment=nil;
parts=nil;
url=nil;
url_string=nil;
NSUInteger final_id = auto_id;
NSLog(@"NOW DISPLAYING AUTOID: autoid is:%lu",(unsigned long)final_id);