没有已知的选择器混淆的类方法

时间:2012-10-18 14:13:43

标签: ios ios5 core-data automatic-ref-counting

我知道这是一个新手问题,但我很困惑。我应该如何从另一个类调用类方法,或者不应该我?

这是我的ClassACoreDataHelper

#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

2 个答案:

答案 0 :(得分:1)

您正在以正确的方式从另一个方法调用类方法,除非方法签名与声明的方法签名不同;

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

+ insertAllObjectsForEntity:andContext:的声明在上面的调用代码中没有最后一个

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

答案 1 :(得分:0)

像:

[ClassName method];

而不是:

[instance method];

在你的例子中就是:

[ClassA pullOfflineDataWithContext];