Error using Protocols
Please refer to the following code:
//
// CacheObjectManagerImpl.h
#import <Foundation/Foundation.h>
//#import "CacheObject.h"
@class CacheObject;
@protocol ICacheObjectManager <NSObject>
typedef enum {
kSTRING,
kBYTEARRAY,
kCACHABLE,
kSTRINGVALUE
} CacheObjType;
CacheObjType *CacheObjectType;
@required
//- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
- (CacheObject *) createCacheObject:(NSString *)data url:(BOOL*)isURL savefile:(BOOL*)saveToFile downloadmgr:(ICacheObjDownloadMgr*) downloadMgr;
//-(CacheObject*) createCacheObject: (Cachable*) dataObject;
@end
@interface CacheObjectManagerImpl : NSObject {
}
@property(nonatomic,assign) id <ICacheObjectManager> delegate;
@end
The next file which uses the above class CacheObject:
//
// CacheManagerImpl.h
#import <Foundation/Foundation.h>
//#import "CacheObject.h"
//#import "CacheObjectManagerImpl.h"
@class CacheObject;
@class CacheObjectManagerImpl;
@protocol ICachePurgeLogic <NSObject>
@required
- (void)runPurge: (NSDictionary*)cacheMap;
@end
@protocol ICacheManager <NSObject>
@required
- (void) put:(NSString*)key cacheobj:(CacheObject*)cacheObj;
- (CacheObject*)get: (NSString*)key;
- (void) clearEntireCache;
- (void) remove: (NSString*)key;
- (void) purge;
- (void) setCachePurgeCustomMgr: (ICachePurgeLogic*)cachePurgeLogic; **//ERROR: error: expected ')' before 'ICachePurgeLogic'**
@end
@interface CacheManagerImpl : NSObject {
NSNumber *timeToLive;
NSDictionary *cacheMap;
ICacheObjectManager *cacheObjMgr; **//ERROR: error: expected specifier-qualifier-list before 'ICacheObjectManager'**
ICachePurgeLogic *purgeManager; **//ERROR: error: expected specifier-qualifier-list before 'ICachePurgeLogic'**
}
@property(nonatomic,assign) id <ICacheManager> delegate;
- (void) getCacheManagerInstance: (NSNumber*) timeToLive;
- (ICacheObjectManager*) createCacheObjManager; **//ERROR: error: expected ')' before 'ICacheObjectManager'**
- (ICacheObjectManager*) getCacheObjManager; **//ERROR: error: expected ')' before 'ICacheObjectManager'**
@end
I am unable to understand why I am getting the above errors. If I include the header files, I get more errors due cyclical header includes. What are the possible work arounds for these compiler errors? Or my code is entirely wrong in the sense that I am passing and returning by pr开发者_如何学运维otocols.
Thanks,
I would start by moving your enum declaration and what appears to be an ivar that is a pointer to your declared type out of your protocol. You shouldn't be declaring types within a protocol declaration. Additionally, if you want to require the classes implementing your protocol to have an object of a certain type, declare a property. Protocols only specify methods that should or need to be implemented.
精彩评论