I am trying to follow this method to create an auto-incrementing field in core data for purposes of syncing with a web server running SQL.
When I try to call this method, however, I get "No known class method..."
This should be trivial so it is very frustrating. Do I have a typo or can anyone point out what I am doing wrong with this simple method call? Thank you.
Item.h
-(NSUInteger)autoId;
Item.m
-(NSUInteger) autoId {
NSURL *url = [[self 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;
return auto_id;
}
AddItem.m
#import "Items.h"
/within save method
NSUInteger autoid = [Items autoId];//error here
The errors are "No known class method for selector autoId" and (warning) "Incompatible pointer to integer conversion initializing NSUInteger aka unsigned long with an expression of type id"
Thanks for any suggestions.
Realized I forgot to instantiate the object before calling it. Since it is an NSManagedObject, it should be instantiated as follows:
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Item" inManagedObjectContext:self.managedObjectContext];
Items *newItem = [[Items alloc]initWithEntity:entity insertIntoManagedObjectContext:self.managedObjectContext];
NSUInteger autoid = [newItem autoId];
Works.