no known class method for selector confusion

10,719

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;
Share:
10,719

Related videos on Youtube

tugce
Author by

tugce

Updated on September 15, 2022

Comments

  • tugce
    tugce over 1 year

    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
    
  • tugce
    tugce over 11 years
    but compiler should not warn me as "no known class method for selector"
  • Simon
    Simon over 11 years
    @tugce Well, actually compiler is right according to Objective-C rule: +insertAllObjectsForEntity:andContext:initCoreData: makes one complete method signature that has quite similar semantic of 'symbol' in C.