You need to create an instance of a sub class of a NSManagedObject
using a NSManagedObjectContext
based on its NSEntityDescription
:
NSManagedObjectContext *managedObjectContext; // Get this from your Core Data stack, probably in the app delegate
HubBrand *brand = [NSEntityDescription insertNewObjectForEntityForName:@"HubBrand" inManagedObjectContext:managedObjectContext];
[brand setBrandName:[NSString stringWithFormat:@"_Custom:, %@", [_txtHubBrand text]]];
See the Creating, Initializing, and Saving a Managed Object section of the doc for more info.
You can also use the sub classes initializer:
NSEntityDescription *entity = [NSEntityDescription entityForName:@"HubBrand" inManagedObjectContext:managedObjectContext];
HubBrand *brand = [[HubBrand alloc] initWithEntity:entity insertIntoManagedObjectContext:managedObjectContext];
But its a bit more wordy!