2011-07-19 164 views
0

請參考下面的代碼:使用錯誤協議

// 
// 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 

它使用上面的類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 

我無法理解爲什麼我收到上述錯誤。如果我包含頭文件,由於包含循環頭文件,我會得到更多的錯誤。這些編譯器錯誤有什麼可能的解決方法?或者我的代碼在協議傳遞和返回的意義上是完全錯誤的。

感謝,

+0

ICachePurgeLogic和ICacheObjectManager聲明在哪裏? – MCannon

回答

0

我會通過移動枚舉聲明,並開始什麼似乎是伊娃是一個指針,你聲明的類型你的協議。你不應該在協議聲明中聲明類型。此外,如果您想要實現您的協議的類具有某種類型的對象,請聲明一個屬性。協議只規定了應該或需要實施的方法。

+0

謝謝保羅的建議。 – XMarshall