I'm trying to implement a database system where an entity contains some methods in its DataClass.m but I cannot call them in my ViewController.m
In the code above I try to call savePersona but the build says
No known class method for selector 'savePersona:etaLabel:indirizzoLabel:contextLabel:'
ViewController.m
#import "ViewController.h"
#import "Giovanni+CoreDataClass.h"
#import "AppDelegate.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
/*
* Event after clicking button Save.
*/
- (IBAction)btnSave:(id)sender {
NSString *nome = _insertName.text;
NSString *eta = _insertAge.text;
NSString *indirizzo = _insertIndirizzo.text;
// Check for all inputs
if ([nome isEqualToString:@""] || [eta isEqualToString:@""] || [eta intValue] <= 0 || [indirizzo isEqualToString:@""] ) {
_resultText.text = @"All fields are required";
return;
}
[Giovanni savePersona:nome etaLabel:[eta intValue] indirizzoLabel:indirizzo contextLabel:[((AppDelegate *)[[UIApplication sharedApplication] delegate]) managedObjectContext]];
}
Giovanni+CoreDataClass.h
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface Giovanni : NSManagedObject
+(void)savePersona: (NSString*)nome etaLabel:(int16_t)eta indirizzoLabel:(NSString*)indirizzo contextLabel:(NSManagedObjectContext *)context;
@end
#import "Giovanni+CoreDataProperties.h"
Giovanni+CoreDataClass.m
#import "Giovanni+CoreDataClass.h"
@implementation Giovanni
+(void)savePersona: (NSString*)nome etaLabel:(int16_t)eta indirizzoLabel:(NSString*)indirizzo contextLabel:(NSManagedObjectContext *)context {
Giovanni *p1 = [[Giovanni alloc] initWithContext:context];
p1.nome = nome;
p1.eta = eta;
p1.indirizzo = indirizzo;
}
In Build Phases I have Giovanni+CoreDataClass.m and Giovanni+CoreDataProperties.m. In Copy Bundle Recources I have DatabaseExample.xcdatamodeld (DatabaseExample is the name of the project)
I have resolved my problem by recreating the project.
Nothing has changed but it seams that XCode encounter some problems on autocreating my entities when i click on Editor -> Create NSManagedObject Subclasses...
I don't know if it's a bug of the latest versione but now the project works fine.