2011-07-06 43 views
0

我需要在目標C創建四個結構結構的目標C

它們分別是:

typedef struct FILE_TRANSFER_REQUEST_STRUCT 
{ 
    uint8_t header[16]; // This would be MD5 of String "SymbolTalk" 
    uint8_t type;  // Type of structure -> FILE_TRANSFER_REQUEST 
    char fileName[512]; 
    int  totalSize; //4096 
    int  chunkSize; //1024 
    int  numChunks; // 4 
}FileTransferRequest; 

typedef struct FILE_TRANSFER_RESPONSE_STRUCT 
{ 
    uint8_t header[16]; // This would be MD5 of String "SymbolTalk" 
    uint8_t type;  // Type of structure -> FILE_TRANSFER_RESPONSE 
    ; 
}FileTransferResponse; 

typedef struct FILE_CHUNK_REQUEST_STRUCT 
{ 
    uint8_t header[16]; // This would be MD5 of String "SymbolTalk" 
    uint8_t type;  // Type of structure -> FILE_CHUNK_REQUEST 

    uint8_t data[1024]; 
    uint8_t chunkNumber; 
    uint8_t chunkSize; 
}FileChunkRequest; 

typedef struct FILE_CHUNK_RESPONSE_STRUCT 
{ 
    uint8_t header[16]; // This would be MD5 of String "SymbolTalk" 
    uint8_t type;  // Type of structure -> FILE_CHUNK_RESPONSE 
    uint8_t chunkNumber; 

}FileChunkResponse; 

但是我不知道有關目標struct.how我可以做this.where我需要創建這個結構(需要避免類)。就是它的目標C類寫file.can任何一個可以告訴我,我怎麼能在另一個class..can任何一個可以幫助我得到這個結構...

+2

看起來對我來說很好。什麼不行? – zneak

+0

ok ... working .... – Christina

回答

4

你會按照你在純C中的方式完全一樣。把它們放在你的一箇中.h文件(無論哪個文件最適合它們的用途),在@interface塊之外。那麼他們將不會成爲任何階級的一部分。

要在一個類中使用它們,只需要#import帶有你的結構定義的.h文件。

+0

http://philjordan.eu/article/strategies-for-using-c++-in-objective-c-projects –

0

只要使用這樣的...

typedef struct FILE_CHUNK_RESPONSE_STRUCT 
{ 
    uint8_t header[16]; // This would be MD5 of String "SymbolTalk" 
    uint8_t type;  // Type of structure -> FILE_CHUNK_RESPONSE 
    uint8_t chunkNumber; 

}FileChunkResponse; 

@class sampleViewController; 

@interface sampleAppDelegate : NSObject <UIApplicationDelegate> { 
    struct FILE_CHUNK_RESPONSE_STRUCT mystructure; 
} 

@property (nonatomic, retain) IBOutlet UIWindow *window; 

@property (nonatomic, retain) IBOutlet sampleViewController *viewController; 

@end 

的Objective-C是c那麼它支持所有的C代碼的超集...如果你想用C++相關類更改文件名改爲.mm .m