tugce tugce - 5 months ago 30
iOS Question

no known class method for selector confusion

I know this is a newbie question, but I am all confused. How should I call class method from another class, or shouldn't I?

Here is my

ClassA
and
CoreDataHelper
:

#import <Foundation/Foundation.h>

@interface ClassA : NSObject {

}

@property (nonatomic, retain) NSString * sessionId;
@property (nonatomic, retain) NSString * token;
@property (nonatomic, retain) NSString * userid;

+ (void) pullOfflineDataWithContext:(NSManagedObjectContext *)managedObjectContext ;
@end


#import "ClassA.h"
#import "CoreDataHelper.h"

@implementation ClassA


+ (void) pullOfflineDataWithContext:(NSManagedObjectContext *)managedObjectContext {

// get Contacts, Accounts, Meetings into Core Data

bool asd =[CoreDataHelper insertAllObjectsForEntity:@"Contact" andContext:managedObjectContext initCoreData:jsonDict];

}
@end

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

@interface CoreDataHelper : NSObject

//For inserting objects
+(BOOL)insertAllObjectsForEntity:(NSString*)entityName andContext:(NSManagedObjectContext *)managedObjectContext;

@end

Answer

You are calling a class method from another in the right way except the method signature is not the same as it is declared;

bool asd =[CoreDataHelper insertAllObjectsForEntity:@"Contact" 
                                         andContext:managedObjectContext 
                                       initCoreData:jsonDict];

The declaration of +insertAllObjectsForEntity:andContext: does not have the last one in the calling code above

+(BOOL)insertAllObjectsForEntity:(NSString*)entityName 
                      andContext:(NSManagedObjectContext *)managedObjectContext;
Comments