2011-05-16 40 views
0

我有一個叫RSTimer類有兩個方法稱爲CreateTimerKillTimer它使用相同的字典對象。我無法在接口中以及在實現中聲明變量。它在聲明中指出並說這不是一個常數。如何使共同聲明的講座的兩種方法>目標C

-(BOOL)KillTimer:(unsigned short)wTimerId 
{ 
    stRs232Timer* pEvent; 
    BOOL bReturn=FALSE; 
    CFDictionaryValueCallBacks cbs = {0,NULL,NULL,NULL,NULL}; 
    CFMutableDictionaryRef cfdict = CFDictionaryCreateMutableNULL,0,&kCFTypeDictionaryKeyCallBacks,&cbs); 
     NSLock* theLock = [[NSLock alloc]init]; 
     if ([theLock tryLock]) { 
     if (CFDictionaryContainsKey(cfdict,&wTimerId)) { 
     free(pEvent); 
     bReturn = TRUE; 
     } 
     [theLock unlock]; 
    } 
return bReturn; 
} 
-(BOOL)CreateTimer:(RS232TimerInterface*)pStack withTimerId:(unsigned short)wTimerId withPeriod:(uint8_t)uPeriod withPersistentState:(BOOL)bPersistent 
{ 

    CFDictionaryValueCallBacks cbs = {0,NULL,NULL,NULL,NULL}; 
    CFMutableDictionaryRef cfdict = CFDictionaryCreateMutable(NULL,0,&kCFTypeDictionaryKeyCallBacks,&cbs); 
    CFNumberRef timerId = CFNumberCreate(NULL,kCFNumberShortType,&wTimerId); 
    [self KillTimer:wTimerId]; 
    NSLock* theLock = [[NSLock alloc]init]; 
    if ([theLock tryLock]) { 
     CFDictionarySetValue(cfdict,&timerId,pEvent); 
     [theLock unlock]; 
    } 

} 

我試過在'init'方法中聲明它。我怎樣才能讓

CFDictionaryValueCallBacks cbs = {0,NULL,NULL,NULL,NULL}; 
CFMutableDictionaryRef cfdict = CFDictionaryCreateMutable(NULL,0,&kCFTypeDictionaryKeyCallBacks,&cbs); 

兩者共同的方法..

回答

2

所引用都由CreateTimer和KillTimer函數應該在你的類的「接口」部分中聲明(通常RSTimer.h任何對象,這應該由實現文件導入)。

像這樣:

interface RSTimer { 
CFDictionaryValueCallBacks cbs; 
CFMutableDictionaryRef cfdict; 
} 
- (void)init; 

你需要以初始化您的會員定義init方法。 (你還沒有提供任何關於哪個是RSTimer基類的細節,所以我假設NSObject)

+0

謝謝...你說的那樣,它的工作原理... – spandana 2011-05-16 12:34:29